#Trying to make a purge command that deletes a certain member's messages

1 messages · Page 1 of 1 (latest)

stray otter
#

I have a purge command already that works, but I wanted to try to implement a function that is optional - so you can delete a certain member's messages too. It doesn't work with other member's except for myself at the moment and when member=me, it only purges 1 message from me too. What am I doing wrong?

@commands.has_permissions(manage_messages=True)
async def purge(self, ctx, amount: int, member:discord.Member=None):
        if member!=None:
          msg=[]
          async for m in ctx.channel.history():
            if len(msg) == amount:
              break
            if m.author.id == member.id:
              msg.append(m)
            await ctx.channel.delete_messages(msg)
            await ctx.respond(f"Messages from {member} has been purged")
            return
        await ctx.respond("Purging messages")
        amount += 1
        await ctx.channel.purge(limit=amount)```
static vigil
#

Because you're breaking the loop before you delete the messages

#

Why are you calling delete_messages inside of the loop anyways?

bright kindle
#

why are you doing delete_messages and purge? only use purge

#

no need to iterate over history too

#

use checks to specify the member

#

.rtfm purge

vague oracleBOT