L
L
Lol Likovic2020-06-29 14:26:28
Python
Lol Likovic, 2020-06-29 14:26:28

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)

Here is the code if it helps
Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey, 2020-06-29
@anerev

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

M
Maxim Nevzorov, 2020-07-04
@fixator10

Use Counterfrom 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 question

Ask a Question

731 491 924 answers to any question