为了账号安全,请及时绑定邮箱和手机立即绑定

“命令”对象没有属性“has_permissions”

“命令”对象没有属性“has_permissions”

莫回无 2023-10-06 10:51:06
@client.command()@commands.has_permissions(administrator=True)async def kick(ctx, member : discord.Member, *, reason=None):    try:        await member.kick(reason=reason)        embed = discord.Embed(colour=maincolour)        embed.title = f"**Member {member.mention} Kicked."        embed.description = f"**Reason** » {reason}.\n**Status** » Successful!"        await ctx.send(embed=embed)    except:            embed = discord.Embed(colour=maincolour)            embed.title = "**Kick not successful."            embed.description = "**Possible Errors:**\n» Insufficient Permissions (Requires Administrator)\n» Error with Bot."            await ctx.send(embed=embed)在线上@commands.has_permissions(administrator=True)错误是'Command' object has no attribute 'has_permissions'。我该如何修复这个错误?这段代码适用于我的朋友。
查看完整描述

1 回答

?
婷婷同学_

TA贡献1844条经验 获得超8个赞

该has_permissions属性不受命令控制。这才是正确的做法。


from discord.ext.commands import has_permissions, MissingPermissions


@client.command()

@has_permissions(administrator = True)  

async def test(ctx):

    pass


@test.error

async def test_error(error, ctx):

    if isinstance(error, MissingPermissions):

        await ctx.send("Looks like you don't have the permissions.")


查看完整回答
反对 回复 2023-10-06
  • 1 回答
  • 0 关注
  • 66 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信