繁体   English   中英

检查角色权限 Discord.py

[英]Check Role Permission Discord.py

我有一个函数,它有一个用于检查用户角色的 for 循环:

for role in ctx.author.roles:

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

谢谢热心帮忙!!!

如果你需要这个来检查作者是否有使用命令的权限。 有一个内置函数来做那个Docs

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!')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM