【问题标题】:discord.py purge command not working and no errordiscord.py purge 命令不起作用且没有错误
【发布时间】:2021-05-17 06:51:30
【问题描述】:

所以我想清除特定成员的消息。这是我的代码。

@commands.command()
async def purge_member(self, ctx, member: discord.Member):
    await ctx.channel.purge(limit=100, check=lambda message: message.author == member)

问题是成员的消息没有被清除。 它也没有显示任何错误。

我尝试了许多其他方法而不是 purge 来删除,但它们都拒绝工作,没有错误

【问题讨论】:

  • 你有on_message 活动吗?
  • 是的,但不在主文件夹中。仅在齿轮中。
  • 您可能应该在您的主要 python 文件中放置一个on_message 事件,并确保同时加载您的 cog 扩展。
  • 有什么理由你有评论标记#?这对您的代码进行了设置,并且不会运行它。
  • 可能有它,因为代码不起作用。当我的不工作时,我通常把它放在那里,这样我以后就可以处理它并且没有任何当前错误。他可能也只是将 cog 中的代码复制并粘贴到这里,所以我不知道他是否忘记删除它。

标签: python discord.py purge


【解决方案1】:

如果您有 on_message 事件,请在其末尾添加 process_commands

# In Cog
@commands.Cog.listener()
async def on_message(m):
    ...
    await self.bot.process_commands(m)

# In Main File
@bot.event
async def on_message(m):
    ...
    await bot.process_commands(m)

如果您没有取消注释代码,请执行此操作,否则它将不起作用

# In Cog
@commands.command()
async def purge_member(self, ctx, member: discord.Member):
    await ctx.channel.purge(limit=100, check=lambda message: message.author == member)

# In Main File
@bot.command()
async def purge_member(ctx, member: discord.Member):
    await ctx.channel.purge(limit=100, check=lambda message: message.author == member)

【讨论】:

  • 即使使用 procces_commands 它也不起作用。我已经试过了。代码未注释。
猜你喜欢
  • 2020-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-16
  • 2019-07-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多