@@ -72,16 +72,41 @@ async def on_message(self, message: discord.Message) -> None:
7272 await self .bot .process_commands (message )
7373
7474 @commands .Cog .listener ()
75- async def on_reaction_add (self , reaction : discord .Reaction , user : discord .User ) -> None :
75+ async def on_raw_reaction_add (self , payload : discord .RawReactionActionEvent ) -> None :
76+ # get reaction from payload.message_id, payload.channel_id, payload.guild_id, payload.emoji
77+ channel = self .bot .get_channel (payload .channel_id )
78+ if channel is None :
79+ logger .error (f"Channel with ID { payload .channel_id } not found." )
80+ return
81+ if isinstance (channel , discord .ForumChannel | discord .CategoryChannel | discord .abc .PrivateChannel ):
82+ logger .error (
83+ f"Channel with ID { payload .channel_id } is not a compatible channel type. How the fuck did you get here?" ,
84+ )
85+ return
86+
87+ message = await channel .fetch_message (payload .message_id )
88+ # Lookup the reaction object for this event
89+ if payload .emoji .id :
90+ # Custom emoji: match by ID
91+ reaction = next (
92+ (r for r in message .reactions if getattr (r .emoji , "id" , None ) == payload .emoji .id ),
93+ None ,
94+ )
95+ else :
96+ # Unicode emoji: match by full emoji string
97+ reaction = discord .utils .get (message .reactions , emoji = str (payload .emoji ))
98+ if reaction is None :
99+ logger .error (f"Reaction with emoji { payload .emoji } not found." )
100+ return
101+
76102 # Block any reactions that are not numbers for the poll
77103 if reaction .message .embeds :
78104 embed = reaction .message .embeds [0 ]
79105 if (
80106 embed .author .name
81107 and embed .author .name .startswith ("Poll" )
82- and reaction .emoji not in [f"{ num + 1 } \u20e3 " for num in range (9 )]
108+ and str ( reaction .emoji ) not in [f"{ num + 1 } \u20e3 " for num in range (9 )]
83109 ):
84- await reaction .remove (user )
85110 await reaction .clear ()
86111
87112 @app_commands .command (name = "poll" , description = "Creates a poll." )
0 commit comments