Search code examples
pythondiscorddiscord.py

Discord.py Clearing Bots Messages


Does Anyone Know How I Can Clear/Purge Just Bots Messages, I Have Made A Purge Command But I Dont Know How To Only Delete Messages Sent By A Bot! Any Help Would Be Appreciated!


Solution

  • Please try to show what you have tried and what problems you are facing next time, this makes it easier to answer questions.

    To solve your problem, you can use Channel.history. Unfortunately, you will have to purge messages manually rather than with channel.purge.

    This code should work for you:

    @client.command()
    async def purge(ctx, limit : int):
      num = 0
      async for m in ctx.channel.history():
        if m.author == client.user:
          await m.delete()
          num += 1
          if num == limit:
            break