【问题标题】:Bot not responding after running the purge command. discord.py运行清除命令后机器人没有响应。不和谐.py
【发布时间】:2021-02-15 20:54:36
【问题描述】:

我遇到过很多这样的问题,目前我也遇到了同样的问题。我的机器人没有响应“清除”命令。我尝试了不同的方法,但仍然无法正常工作。我在命令的开头和结尾打印了两次,似乎第一个工作正常,但第二个没有。那是怎么回事?

    @commands.command()
    async def clear(self, ctx, *, limit=100):
        channel = ctx.message.author.discord.text_channel.name
        await channel.purge(limit = amount)

这就是代码。它也在一个齿轮中。我还提到我打印了两次:

    @commands.command()
    async def clear(self, ctx, *, limit=100):
        print("x")
        channel = ctx.message.author.discord.text_channel.name
        await channel.purge(limit = amount)
        print("y")

运行命令时基本上只有 x 被打印出来。所以问题必须是await channel.purge(limit = amount。有人有什么想法吗?任何答案将不胜感激! 另外我忘了说没有错误。

【问题讨论】:

    标签: python python-3.x discord.py


    【解决方案1】:

    您的函数存在两个问题。 正如 RandomGuy 的回答所示,您需要 limit = limit,因为您已将清除限制变量声明为 limit 而不是 amount

    您还试图从频道名称中清除,而不是从频道对象中清除。您需要更改此行:

    channel = ctx.message.author.discord.text_channel.name
    

    到:

    channel = ctx.channel
    

    【讨论】:

      【解决方案2】:

      金额变量未定义您应该使用限制

      await channel.purge(limit = limit)
      

      【讨论】:

      • 我确实改变了它,但它似乎仍然有同样的问题。
      猜你喜欢
      • 2021-06-17
      • 2021-11-21
      • 2019-04-13
      • 2021-07-07
      • 1970-01-01
      • 2020-10-18
      • 2021-12-03
      • 2021-08-18
      相关资源
      最近更新 更多