8auuuuuer
8auuuuuer

Reputation: 51

Discordpy purging messages from a specific user

Currently I'm trying to delete messages that are sent by a certain user, however I get the error:

Command raised an exception: AttributeError: 'list' object has no attribute 'author'

I'm unsure why this is happening, any help would be greatly appreciated.

@client.command()
async def message_test(ctx, channel: discord.TextChannel):

    def user_filter(message):
        return message.author.id == 627862713242222632

    messages = [m.content async for m in channel.history().filter(user_filter)]
    print(messages)  # prints the list we get from the line above
    me = messages.author == 627862713242222632
    deleted = await channel.purge(limit=100, check=me)
    await channel.send('Deleted {} message(s)'.format(len(deleted)))

Upvotes: 0

Views: 240

Answers (1)

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15689

The code you wrote doesn't make any sense at all. Here's how to delete 100 messages of a specific user id.

def is_user_message(message):
    return message.author.id == some_user_id

await channel.purge(limit=100, check=is_user_message)

Upvotes: 1

Related Questions