英文:
discord.py default errors handling
问题
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
循环?
英文:
discord.py has it's own error handling, but I need to handle Python error. Example:
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)
on command use i get Command raised an exception: NameError: name 'c' is not defined
in terminal, but can i handle it with
@client.event
async def on_error(ctx, error):
or I need to use try except
cycle in command?
答案1
得分: 0
问题已关闭。对于此问题的答案:
if isinstance(error, commands.CommandInvokeError):
if isinstance(error.original, NameError):
embed.add_field(name="name", value="value", inline=False)
英文:
Question closed. Answer for this one:
if isinstance(error, commands.CommandInvokeError):
if isinstance(error.original, NameError):
embed.add_field(name = "name", value = "value", inline = False)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论