How to send a message in an "async def on_raw_reaction_add" discord.py?

Viewed 144
async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent):
      global verstuurd_id
      global game
      print(payload)
      #await message.channel.send('Er is een emoji toegevoegd')
      if payload.message_id == verstuurd_id and game == True and payload.user_id != self.user.id:
        print("Er is gereageerd")
        if payload.emoji.name =='➡':
          pass
          #await payload.channel_id.send('You answered right')
      else:
        print('Er is iets fout gegaan')

I want to send a message in the discord channel but I am not able to in an async def on_raw_reaction_add. Does anyone know how to?

1 Answers

In the on_raw_reaction_add event you receive a discord.RawReactionActionEvent object. This object doesn't has an attribute that would give you a channel object. But it does has channel_id which you can use to get an actual discord.TextChannel object to send your message.

You can also get a discord.Member object of the user who added the reaction.

You are attempting to call send() on an int which is payload.channel_id in this case. To get the channel object(since you have the channel id):

channel = bot.get_channel(payload.channel_id)
# Or
channel = discord.utils.get(member.guild.text_channels, id=payload.channel_id)

Now you can send the message by calling send() on that object:

 async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent):
      global verstuurd_id
      global game
      print(payload)
      if payload.message_id == verstuurd_id and game == True and payload.user_id != self.user.id:
        print("Er is gereageerd")
        if payload.emoji.name =='➡':
          channel = bot.get_channel(payload.channel_id)
          await channel.send('You answered right')
      else:
        print('Er is iets fout gegaan')
Related