Подсчет реакций на сообщения DiscordPython

Программы на Python
Anonymous
Подсчет реакций на сообщения Discord

Сообщение Anonymous »


I am trying to count the number of reactions each user has done in a channel. The typical process is to find a message then get the

Код: Выделить всё

reaction
and then use the

Код: Выделить всё

reaction.users()
method to get the users that have reacted to this message. But this is awfully slow for multipble messages. Is there a faster way of doing this?
I can already get 100 messages at a time with the channel history but then I have to get the user by asking the API for every message. This can't be the only way, right?
This is the code I have so far:

Код: Выделить всё

count = 0

limit = 100  # Adjust limit as needed (max 100)
messages = []
after = None
last_after = None
while True:
history = ctx.channel.history(limit=limit, before=after)

async for message in history:
messages.append(message)

after = messages[-1]

if after == last_after:
break

last_after = after

if count%10:
print("Crawled " + str(count*100) + " Messages")

count+=1

reactions = {}

for message in messages:
if len(message.reactions) == 0:
continue

for reaction in message.reactions:
if reaction.emoji != "🌽":
continue

async for user in reaction.users():
try:
reactions[user.id] = (user.display_name, reactions[user.id][-1]+1)
except:
reactions[user.id] = (user.display_name, 1)


Источник: https://stackoverflow.com/questions/781 ... n-counting

Вернуться в «Python»