检查角色权限Discord.py

时间:2020-11-10 07:26:04

标签: python discord discord.py

我有一个具有for循环的功能,该功能可以检查用户角色:

for role in ctx.author.roles:

现在,我要检查“角色”是否具有Manage_Channels权限

感谢助手!

1 个答案:

答案 0 :(得分:0)

如果需要此命令,以检查作者是否有权使用该命令。 Docs有一个内置功能。<​​/ p>

from discord.ext.commands import has_permissions

@bot.command()
@commands.has_permissions(manage_channels=True)
async def test(ctx):
    await ctx.send('You can manage channels.')

对于错误消息

from discord.ext.commands import MissingPermissions

@test.error
async def test_error(error, ctx):
    if isinstance(error, MissingPermissions):
        await ctx.send(f'Sorry {ctx.author.mention}, you do not have permissions to do that!')