Trigger on_reaction_add
on messages from history.
#8369
-
I am writing a small bot that should display if a user added a reaction to messages. The problem is that class ExampleClient(discord.Client):
async def on_ready(self):
for channel in discord.Client.get_all_c:hannels(self):
channel = await self.fetch_channel(channel.id)
print(f"Channel {channel.name} with ID {channel.id}")
if hasattr(channel, "history"):
async for message in channel.history(limit=10):
message = await channel.fetch_message(message.id)
print(f"cached {message.id}") Which does show me the messages I want to react on. Still, no Simple test case of my async def on_reaction_add(self, reaction: discord.Reaction, user):
print(f'User {user} added reaction {reaction} in channel {reaction.message.channel}')
bot_channel = discord.Client.get_channel(self, 1011016620321296425)
await bot_channel.send(content=f"A rating of {reaction} was placed in {reaction.message.channel} for link {reaction.message.content}") |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Beta Was this translation helpful? Give feedback.
on_reaction_add
is only triggered by messae that are available in cache of the bot. You should instead be leveraging theon_raw_reaction_add
event which gets triggered regardless of a message's cache presence. However this event does not take a reaction, user pair as argument but instead takes a payload that includes appropriate information for you to handle the event as you like