S_c*_*ted 3 discord discord.py
我已经看到过允许某个角色使用命令的变体。但是,我试图实现完全相反的目标:How to disallow a certain role from using a command。
我搜索了堆栈溢出并没有找到答案,也没有在官方 discord.py 文档中找到答案。任何形式的帮助表示赞赏。
author.roles 返回一个列表,discord.Role因此只需检查您指定的角色是否包含在该列表中,如果包含,请提前退出命令。
使用角色 ID(首选)
@bot.command()
async def command_without_specific_role(ctx):
if role_id in [role.id for role in ctx.author.roles]:
return
...
Run Code Online (Sandbox Code Playgroud)
使用角色名称
@bot.command()
async def command_without_specific_role(ctx):
if role_name in [role.name for role in ctx.author.roles]:
return
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
729 次 |
| 最近记录: |