如何退出或中断discord.py中的命令 [英] how I can exit or break a command in discord.py

查看:35
本文介绍了如何退出或中断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')

这篇关于如何退出或中断discord.py中的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆