【发布时间】:2020-11-10 22:29:38
【问题描述】:
我有一个带有用于检查用户角色的 for 循环的函数:
for role in ctx.author.roles:
现在,我想检查“角色”是否有权限 Manage_Channels
感谢大家的帮助!!!
【问题讨论】:
-
您是否需要阻止非管理员使用该命令?
标签: python discord discord.py
我有一个带有用于检查用户角色的 for 循环的函数:
for role in ctx.author.roles:
现在,我想检查“角色”是否有权限 Manage_Channels
感谢大家的帮助!!!
【问题讨论】:
标签: python discord discord.py
如果你需要这个来检查作者是否有使用该命令的权限。有一个内置函数可以做到这一点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!')
【讨论】:
Docs的链接 这是那里的例子,试试看它是否适合你。
@clear.error async def clear_error(error, ctx): if isinstance(error, MissingPermissions): await ctx.send(f'Sorry {ctx.author.mention}, you do not have permissions to do that!')