我如何退出或中断 discord.py 中的命令
how I can exit or break a command in discord.py
我想知道是否有办法在匹配条件时中断命令
例如我想在用户不是管理员时中断此命令
@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)
只需将权限替换为管理员并将此装饰器放在您的函数上。
这是我的使用方法
@commands.bot_has_guild_permissions(manage_roles=True)
async def remove(
self, ctx, roles: Greedy[RoleConverter], members: Greedy[MemberConverter]
):
我想知道是否有办法在匹配条件时中断命令
例如我想在用户不是管理员时中断此命令
@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)
只需将权限替换为管理员并将此装饰器放在您的函数上。
这是我的使用方法
@commands.bot_has_guild_permissions(manage_roles=True)
async def remove(
self, ctx, roles: Greedy[RoleConverter], members: Greedy[MemberConverter]
):