【问题标题】:discord.py default errors handlingdiscord.py 默认错误处理
【发布时间】:2023-02-11 16:35:27
【问题描述】:

discord.py 有它自己的错误处理,但我需要处理 Python 错误。例子:

def create(a: str, b: str, c: str):
    list = [a, b, c]
    return list

@client.command()
async def test(ctx):
    a = "First"
    b = "Second"
    list = create(a, b, c)
    await ctx.send(list)

在命令使用时,我在终端中得到Command raised an exception: NameError: name 'c' is not defined,但我可以用它来处理吗

@client.event
async def on_error(ctx, error):

或者我需要在命令中使用try except循环?

【问题讨论】:

  • 你可以使用你可以使用 try 和 except 块

标签: python error-handling discord.py


【解决方案1】:

问题关闭。这个问题的答案:

if isinstance(error, commands.CommandInvokeError):
        if isinstance(error.original, NameError):
            embed.add_field(name = "name", value = "value", inline = False)

【讨论】:

    猜你喜欢
    • 2016-09-02
    • 1970-01-01
    • 2015-07-13
    • 2014-10-14
    • 1970-01-01
    • 2013-06-19
    • 2020-09-03
    • 2019-01-25
    • 1970-01-01
    相关资源
    最近更新 更多