Answer the question
In order to leave comments, you need to log in
How to make the bot read the messages of different users and display them separately?
In general, such garbage that the bot counts the number of messages from all users, but it needs to be from each, but separately, how to do this ??
@client.event
async def on_message(message):
if message.author == client.user:
return
else:
global counter
counter +=1
print('Message from {0.author}: {0.content}'.format(message))
user = message.author
msg = message.content
print(user, msg)
Answer the question
In order to leave comments, you need to log in
I would first create a name : messages dictionary, after which I would check in the for loop whether name is in the dictionary, if not, then create it, and if there is, add it to the number of values, and you can already work with the dictionary as you like
Use Counter
from standard library collections
: https://docs.python.org/3/library/collections.html...
from collections import Counter
...
msg_count = Counter()
@client.event
async def on_message(msg):
if msg.author == client.user:
return
global msg_count
msg_count[msg.author.id] += 1
print(f"Message by {msg.author}: {msg.content}")
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question