它还没有完成,但我正在向我的机器人添加投票功能。但是,如果没有提供任何问题或选项,我希望能够做一些事情。我不想做一个错误处理程序,因为我觉得它远远超出了我所知道的。
@bot.command(pass_context=True)
async def poll(ctx, *, msg):
try:
split_msg = msg.split(";")
question = split_msg[0]
option1 = split_msg[1]
option2 = split_msg[2]
embed = discord.Embed(title="Question", description=question)
embed.add_field(name="Option 1", value=option1, inline=True)
embed.add_field(name="Option 2", value=option2, inline=True)
error = discord.Embed(title=":warning: Incorrect Syntax!", description="Usage: {}poll <question>; <option1>; <option2>".format(prefix))
await bot.say(embed=embed)
except CommandInvokeError:
print("CommandInvokeError")
否。CommandInvokeError
是当命令执行引发任何未捕获的错误时由机器人调用命令引发的异常。您的代码不会引发CommandInvokeError
,因此您无法捕获它。如果您检查完整的错误消息,您可能会发现您的CommandInvokeError
错误是由另一个错误引起的,您可以捕获该错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句