0

I am trying to make a discord bot that finds emojis in messages in a channel and then reacts with these messages.

My code is:

if message.channel.id == 645647298423613453:
      custom_emojis = re.findall(r'<:\w*:\d*>', message.content)
      custom_emojis = [e.split('<')[1].replace('>', '') for e in custom_emojis]
      for item in custom_emojis:
         await message.add_reaction(item)

and it perfectly reacts with all custom emojis (I used resources from here and here). So, now I have to implement the same for normal emojis.

The first issue is how to find if there are any of them in the message sent. In threads like this or this it is used the module emoji.UNICODE_EMOJI. However, as it is said here you cannot use it, right?

The second issue is that the only way that I have found how do react with them is this.

I know that await message.add_reaction("") works perfectly but I lack the icon itself.

When I run this:

msg = message.content.split()
print("msg is ", msg)

I get this list: msg is ['', '️\u200d⚧️', 'dasdass', 'aadsdasasd', '<:test2:1066037921007808612>'] while my original discord message was the knife icon, Trans flag, two random string and a custom emoji.

So the final question is: How do I get the non-custom emojis, and how do I react with them in the format that I have extracted them.

For reference my code is hosted in replit.com and I have used this source to make the bot.

Skapis9999
  • 402
  • 6
  • 14
  • 1
    Get the list of non-custom emojis using the `emojis` library as you can see in [this answer](https://stackoverflow.com/a/63909716/20214407). Then iterate the list (if not empty) and add a reaction per element (emoji) in the list: `[await message.add_reaction(r) for r in emojis.get(message.content)]` – Jabro Jan 23 '23 at 09:55
  • @Jabro thank you for your advice. I did exactly what you have said but I get an error saying `AttributeError: module 'emoji' has no attribute 'UNICODE_EMOJI'` obviously refering to the `emoji.UNICODE_EMOJI['en']` command. This was my Issue 1 above. – Skapis9999 Jan 23 '23 at 15:59
  • 1
    Check the link I added above. I mean [this answer](https://i.imgur.com/rf6en0v.png) – Jabro Jan 24 '23 at 08:07
  • ok thank you. So I added `import emojis` `emoji_reactions = emojis.get(s)` `for item in emoji_reactions: await message.add_reaction(item)` and it worked for all non custom emojis. So my solution and this compined work for everything. – Skapis9999 Jan 24 '23 at 14:25

1 Answers1

0

So the solution I implemented is this:

First I add the custom emojis:

custom_emojis = re.findall(r'<:\w*:\d*>', message.content)
      custom_emojis = [e.split('<')[1].replace('>', '') for e in custom_emojis]
      print(custom_emojis)
      print(message.content)
      for item in custom_emojis:
         await message.add_reaction(item)

And then I add the built in emojis:

s=message.content
      emoji_reactions = emojis.get(s)
      for item in emoji_reactions:
         await message.add_reaction(item)

This implementation has a small issue. You do not react with the emojis in the right order. Since there are two different sequential commands. But at the end there are all the reactions I want.

Skapis9999
  • 402
  • 6
  • 14