discord.py How to set a kick command such that only an administrator can use it?

北战南征 提交于 2021-02-05 06:10:04

问题


Here is my code -

@client.command()
@client.command.has_permissions(administrator=True)
async def kick(ctx, member: discord.Member):
    await member.kick()
    await ctx.message.add_reaction("✅")
    await ctx.send(f"{member.name} has been kicked by {ctx.author.name}!")

    await log_channel.send(f"{ctx.author.name} has kicked {member.display_name}")

It shows the following the following error -

Traceback (most recent call last):
  File "C:/Users/Gacha/Desktop/Python Bot/bot.py", line 56, in <module>
    @client.command.has_permissions(administrator=True)
AttributeError: 'function' object has no attribute 'has_permissions'

I dont know why its showing this, I saw someone using this and it worked for him. ;-;


回答1:


Its @commands.has_permissions(administrator=True) instead of @client.command.has_permissions(administrator=True)

And I wonder where you saw someone else using it 🤔



来源:https://stackoverflow.com/questions/63480249/discord-py-how-to-set-a-kick-command-such-that-only-an-administrator-can-use-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!