检查用户是否在discord.py中具有权限
问题描述:
我正在为discord.py僵尸程序执行kick命令。以下是kick命令可能是的一些代码:
I am making a kick command for my discord.py bot. Here is some code that the kick command might be:
async kick_command(self, ctx, userName: discord.User):
prefix_used = ctx.prefix
alias_used = ctx.invoked_with
text = msg[len(prefix_used) + len(alias_used):]
if discord.User permissions = "admin":
try:
kick(User)
except Exception as e:
ee = "Error: " + e
await ctx.send_message(content=ee)
我很确定if语句和 kick(User)
是无效的语法。您能帮我吗?
I am pretty sure the if statement and kick(User)
are invalid syntax. Can you help me?
我的代码:
单击此处
答
请尝试以下操作:
Try this:
@bot.command()
@has_permissions(kick_members=True)
async def kick(self, ctx, Member: discord.Member):
await bot.kick(Member)
@kick.error
async def kick_error(error, ctx):
if isinstance(error, MissingPermissions):
await ctx.send("You don't have permission to do that!")
不要忘记从discord.ext.commands导入 has_permissions
::import has_permissions
don't forget to import the has_permissions
: from discord.ext.commands import has_permissions