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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With