问题
So basically what I am doing is trying to write a very basic kick and ban command to use for my discord bot. I've looked through many different tutorials and similar questions asked, but I simply cannot find a fix to this.
@bot.command()
@commands.has_permissions(kick_members=True)
async def kick(ctx, user: discord.Member, *, reason=None):
await ctx.kick(reason=reason)
await ctx.send(f"{user} has been kicked successfully")
When I have the bot up and running, everyone is able to kick everybody else regardless of whether they have permissions to kick members or not, even though I have specified it to check if the user is able to kick people. I want it so that if a user does not have permissions to kick members, they shouldn't be able to kick anyone. I am fairly new to coding, and any help is appreciated. If anyone would like to check for the rest of the code in my program, I am happy to post it, but for now I don't see a reason to have to.
回答1:
await ctx.kick(reason=reason)
You're trying to kick the context. Kick the member instead:
await user.kick(reason=reason)
来源:https://stackoverflow.com/questions/62055224/commands-has-permissions-not-checking-for-permissions