【发布时间】:2020-10-30 10:36:05
【问题描述】:
下面的代码命令突然停止工作。在 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...")
有什么方法可以打印错误消息吗? 或者您对导致此问题的原因有什么建议?
【问题讨论】:
标签: python python-3.x discord discord.py