skip to Main Content

I’m dealing with a small project, I decided to add emoji to make the visual a little better, but I couldn’t send it. I tried Unicodes like "U000203C" or even tried to copy the emoji and past it but still can’t do it. Is there any way that I can send emoji?

Unicode

exchange_msg = "TRY TO USD: "+ USDTORTY, "PERCANTAGE: " +  USDTORTYPERCENTAGE + u'U000203C'
update.message.reply_text(exchange_msg)

Copy-Paste

exchange_msg = "TRY TO USD: "+ USDTORTY, "PERCANTAGE: " +  USDTORTYPERCENTAGE + u'🚨'
update.message.reply_text(exchange_msg)

The outputs of the codes I tried are as follows below.

["TRY TO USD: 7.8645", "PERCANTAGE: -0.0151 (-0.19%)ud83dudea8"]

3

Answers


  1. The reply message is a tuple

    exchange_msg = "TRY TO USD: "+ USDTORTY, "PERCANTAGE: " +  USDTORTYPERCENTAGE + u'🚨'
    
    # print type: <class 'tuple'>
    print(type(exchange_msg))
    # print second value: PERCANTAGE: USDTORTYPERCENTAGE 🚨
    print(exchange_msg[1])
    # print second value type: <class 'str'>
    print(type(exchange_msg[1]))
    

    You can easily use emoij in text messages as long a they are part of a String.
    You could change your code to use a single string as response (which is a good way to map a reply) or alternatively access directly the tuple values

    # replacing comma with a space
    exchange_msg = "TRY TO USD: " + 'USDTORTY' + " " + "PERCANTAGE: " + 'USDTORTYPERCENTAGE ' + '🚨'
    
    Login or Signup to reply.
  2. I have a running bot and I use a lot of emojis. I use https://www.iemoji.com/ to find the Python Src to the emoji I want to use, then I code.

    This is my way to do it:

    def emojis (update, context):
        msg = 'U0001F916 This is a Robot face!n'
        msg += 'uE404 This is a smiling face!'
        context.bot.send_message(message_id = update.message.message_id,
                                 chat_id = update.message.chat_id,
                                 text = msg)
    
    Login or Signup to reply.
  3. There are some ways to show your emojis in python.

    1. By emoji name (You can find your names in this unicode.org)

      print('N{Sauropod}')
      
    2. By emoji unicode (It should be 8 characters, hence, put some zeros after U)

      print('U0001F534')
      
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search