【问题标题】:Discord bot commands stopped working all of a suddenDiscord 机器人命令突然停止工作
【发布时间】: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


    【解决方案1】:

    所以我进入了我的隐私设置,并关闭了服务器成员的 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)
    

    【讨论】:

      猜你喜欢
      • 2021-09-04
      • 2023-03-29
      • 2019-05-01
      • 1970-01-01
      • 2021-07-30
      • 2021-11-14
      • 2021-07-07
      • 1970-01-01
      • 2018-05-06
      相关资源
      最近更新 更多