【问题标题】:Discord.py: How would you restrict a certain command to a role or people with specific permissions?Discord.py:您如何将某个命令限制为某个角色或具有特定权限的人?
【发布时间】:2021-04-16 16:43:19
【问题描述】:
有人可以说明您如何限制,例如,下面的命令让我们说一个名为“主持人”的角色,还是只对拥有踢球权限的人说?我不太明白它是如何工作的。
@client.command()
async def kick(ctx, member:discord.Member)
await member.kick()
await ctx.send(f'{member.mention} has been kicked.')
【问题讨论】:
标签:
python
discord
discord.py
【解决方案1】:
要将命令限制为某些名为“主持人”或“管理员”的角色,请使用 has_any_role
@client.command(pass_context=True)
@commands.has_any_role("Moderator", "Admin")
async def kick(ctx, member: discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.channel.send(f'{member.mention} has been kicked.')
要将命令限制为角色的某些权限,例如,如果角色有管理员,您可以使用 has_permissions
@client.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def kick(ctx, member: discord.Member, *, reason=None):
await member.kick(reason=reason)
await ctx.channel.send(f'{member.mention} has been kicked.')