猿问

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

@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'。


我该如何修复这个错误?这段代码适用于我的朋友。


莫回无
浏览 67回答 1
1回答

婷婷同学_

该has_permissions属性不受命令控制。这才是正确的做法。from discord.ext.commands import has_permissions, MissingPermissions@client.command()@has_permissions(administrator = True)  async def test(ctx):    pass@test.errorasync def test_error(error, ctx):    if isinstance(error, MissingPermissions):        await ctx.send("Looks like you don't have the permissions.")
随时随地看视频慕课网APP

相关分类

Python
我要回答