我想知道当命令与条件匹配时,是否有方法中断命令
例如,当用户不是管理员时,我想中断这个命令
@client.command
async def test_me(ctx):
user = ctx.author.id
if user not in admins:
await ctx.send("you're not admin")
break command
else:
None
await ctx.send('Hi admin')
所以我不想在if语句中添加全部内容,这就是我询问的原因
不能break
函数。您需要处于循环中才能使用break,如果else
语句为空,也不需要它。
如果您只想退出该功能,可以使用return
像这样的东西应该工作
@client.command
async def test_me(ctx):
user = ctx.author.id
if user not in admins:
await ctx.send("you're not admin")
return
await ctx.send('Hi admin')
他们有一个内置的系统来要求权限
@commands.has_guild_permissions(manage_roles=True)
只需将权限替换为administrator,并将此装饰器放置在您的函数上。
以下是我如何使用它
@commands.bot_has_guild_permissions(manage_roles=True)
async def remove(
self, ctx, roles: Greedy[RoleConverter], members: Greedy[MemberConverter]
):