Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the number of messages sent by a user in a discord server without discord.py?

Using discord's search function manually, you can enter something like from:user#3456 and it will show you how many messages they've sent on the server (at least, messages you have access to).

I've been told there is no way to get this information through discord.py, but is there really no way to get that data at all? Would I have to resort to a web scraping tool?

To be clear, I have looked at history() already. What I'm looking for is a way to access the search function that Discord already has.

like image 270
apc518 Avatar asked Oct 11 '25 11:10

apc518


1 Answers

This is actually possible using discord.TextChannel.history. Here is an example:

userMessages = []

userID = 1234567890 # Change this to the ID of the user you are looking messages for
channelID = 1234567890 # Change this to the channel ID of the messages you want to check for

channel = client.get_channel(channelID)
user = discord.utils.find(lambda m: m.id== userID, channel.guild.members)

async for message in channel.history():
    if message.author == user:
        userMessages.append(message.content)

print(len(userMessages)) # Outputs total user messages

Make sure you replace 1234567890 with the corresponding IDs.

I've added an array which also shows all the user messages, if you prefer you can remove that and have it increment a counter instead.

like image 76
creed Avatar answered Oct 16 '25 02:10

creed