Thundo
Thundo

Reputation: 173

Deleting a specific person messages

Now it only delete the "content" last messages:

@commands.command()
    @commands.has_permissions(manage_guild=True)
    async def clear(self, ctx, content:int):
            await ctx.message.delete()
            if content > 0:
                await ctx.channel.purge(limit=content)
                if content == 1:
                    title = f'Usunięto {content} wiadomość'
                    colour = discord.Colour.blue()
                else:
                    title = f'Usunięto {content} wiadomości'
                    colour = discord.Colour.blue()
            else:
                title = 'Hej! Wartość nie może być mniejsza od 0!'
                colour = discord.Colour.red()
            clear = discord.Embed(
            title = title,
            colour = colour
            )
            clear.set_author(name=ctx.bot.user.name, icon_url=ctx.bot.user.avatar_url)
            clear.set_footer(text=version)
            textMsg = await ctx.send(embed=clear)
            await textMsg.delete(delay=2)

I want to make bot delete only specific person (e.g. "!clear 5 @Thundo#0000 <= mention) - will delete only last five Thundo's messages and it won't delete other messages

Upvotes: 1

Views: 107

Answers (1)

KickBull
KickBull

Reputation: 111

Use the check kwarg of the purge function. It takes in a function with one parameter- the message. You can make that function return True only if the message.author is the one whose messages you're trying to delete. Pass that function to the check kwarg. You can also pass the number of messages, that should be deleted, to the limit kwarg, as an integer. And boom, that's it

Upvotes: 1

Related Questions