下面的代码命令突然停止工作。在pycharm中,我没有任何错误,并且我的on_message事件下已经有await bot.process_commands(message)
。
您会看到有try:
和except:
语句,我添加了这些语句,并且它们确实失败并发送了这些错误消息。
@bot.command()
@commands.cooldown(1, 10, commands.BucketType.user)
async def report(ctx, user, reason):
try:
if ctx.channel.id == 730496513255669881:
# player DM side
embed = discord.Embed(title="Your Guild Report has Been Submitted!", color=0xb92d5d)
embed.add_field(name="You Reported: " + user, value="Report Reason: " + reason, inline=True)
embed.set_footer(text="You will be contacted about your report within 1 to 2 days")
await ctx.author.send(embed=embed)
await ctx.channel.purge(limit=1)
except:
await ctx.channel.send("Uh oh!")
# report command errors
@report.error
async def report_error(ctx, error):
try:
if ctx.channel.id == 730496513255669881:
if isinstance(error, commands.MissingRequiredArgument):
if error.param.name == 'user' or 'reason':
embed = discord.Embed(title="Insufficient Arguments!", color=0xb92d5d)
embed.set_footer(text="Please use !report (player/user) (reason)")
await ctx.author.send(embed=embed)
await ctx.channel.purge(limit=1)
if isinstance(error, commands.CommandOnCooldown):
embed = discord.Embed(title="Your on a Cooldown!", color=0xb92d5d)
embed.set_footer(text="There is a 1 day cooldown for using this command, and it isn't over yet")
await ctx.author.send(embed=embed)
await ctx.channel.purge(limit=1)
except:
await ctx.channel.send("Umm error...")
有什么办法可以我以某种方式打印错误消息吗? 还是您对导致此问题的原因有什么建议?
答案 0 :(得分:0)
因此,我进入了我的隐私设置,然后关闭了服务器成员DM。 解决了问题。
如何从失败的命令中获取错误:
@bot.event
async def on_command_error(ctx, exc):
etype = type(exc)
trace = exc.__traceback__
verbosity = 4
lines = traceback.format_exception(etype, exc, trace, verbosity)
traceback_text = ''.join(lines)
await ctx.channel.send(traceback_text)