How to send emoji in Telegram bot with python?
Asked Answered
H

3

5

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%)\ud83d\udea8"]
Halfpenny answered 20/10, 2020 at 19:36 Comment(0)
T
3

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 ' + '🚨'
Thuja answered 21/10, 2020 at 16:6 Comment(0)
E
9

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)
Enrapture answered 2/12, 2020 at 21:24 Comment(1)
To add to it, one need to click on the detail page of a emoji and scroll down: iemoji.com/view/emoji/506/symbols/double-exclamation-mark :) – Vincennes
T
3

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 ' + '🚨'
Thuja answered 21/10, 2020 at 16:6 Comment(0)
C
2

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')
    
Capuche answered 16/6, 2022 at 12:38 Comment(0)

© 2022 - 2025 β€” McMap. All rights reserved.