[英]Discord.py: How would you restrict a certain command to a role or people with specific permissions?
Could someone show how you'd restrict, for example, the following command to lets say a role named 'Moderator' or only to people that have kick permissions?有人可以展示你如何限制,例如,下面的命令让我们说一个名为“主持人”的角色,或者只给有踢权限的人吗? I don't quite understand how that'd work.
我不太明白那是如何工作的。
@client.command()
async def kick(ctx, member:discord.Member)
await member.kick()
await ctx.send(f'{member.mention} has been kicked.')
To restrict commands to certain roles named "Moderator" or "Admin" use has_any_role要将命令限制为某些名为“主持人”或“管理员”的角色,请使用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.')
To restrict commands to certain permissions of roles for example if a role has administrator you use has_permissions要将命令限制为角色的某些权限,例如,如果角色有管理员,您可以使用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.')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.