0

I'm collecting a user's message with the client.wait_for command, and I wanted to know a way that I can identify if the message is an emoji (either default or custom). I've attempted to use guild.fetch_emoji and client.get_emoji in order to detect whether it is a proper emoji. Will I have to put the message through multiple functions?

while continue_function:
    user_msg = await self.bot.wait_for('message', check=lambda message: message.author == ctx.author and message.channel == ctx.channel)
    emoji = self.bot.get_emoji(user_msg.content)
    emoji2 = ctx.guild.fetch_emoji(user_msg.content)
    print(emoji,emoji2)
N Period
  • 25
  • 3
  • `self.bot.get_emoji()` doesn't take a string. It takes a discord ID (emoji ID) which it will then search for through the bot's cache. Same thing with `guild.fetch_emoji` – 12944qwerty Apr 19 '21 at 04:24
  • 1
    Does this help to answer your question? [How check on\_message if message has emoji for discord py?](https://stackoverflow.com/questions/54859876/how-check-on-message-if-message-has-emoji-for-discord-py) – Bagle Apr 19 '21 at 06:00

1 Answers1

2

As @12944qwerty said, you cannot use a string to fetch the the emoji. However if you want to catch messages that just contain an emoji, for exemple "", as stated here you can use from emoji import UNICODE_EMOJI to have a list of all unicode emojis, then you can find if there is an emoji in your message by using this function

def is_emoji(content):
    for emoji in UNICODE_EMOJI:
        if content == emoji:
            return True
    return False

You can modify this function if you want to check for multiple emojis or just checking if emoji in content instead, it depends on waht you need.

This won't work for custom emojis, or emojis that do not exist for unicode. For custom emoji you can use this RegEx <:\w+:(\d+)> to get the id of the custom emoji that you'll be able to use with get_emoji() or fetch_emoji(). Use this resource for more information about RegEx in python

Nathan Marotte
  • 771
  • 1
  • 5
  • 15