skip to Main Content

This is my code:

import telebot

BOT_TOKEN = '-'
bot = telebot.TeleBot(BOT_TOKEN)

@bot.message_handler(func=lambda message:True)
def thumbs_up(message):
    bot.set_message_reaction(message.chat.id, message.id, '👍')


if __name__ == '__main__':
    bot.polling()

And this is the error I get:

    payload['reaction'] = json.dumps([r.to_dict() for r in reaction])
                                      ^^^^^^^^^
AttributeError: 'str' object has no attribute 'to_dict'

I don’t understand how I can use a JSON list like the docs say:

https://pytba.readthedocs.io/en/latest/sync_version/index.html#telebot.TeleBot.set_message_reaction

https://core.telegram.org/bots/api#setmessagereaction

It also says in the docs that the reaction parameter is optional but I get an error if I don’t include it.

2

Answers


  1. The reaction should be a list, not a single emoji.

    Use it like so:

    from telebot.types import ReactionTypeEmoji
    
    bot.set_message_reaction(message.chat.id, message.id, [ReactionTypeEmoji('👍')], is_big=False)
    
    Login or Signup to reply.
  2. 0stone0 is absolutely right. But if you want to use constants instead of typing strings you can do it this way:

    from telegram import ReactionTypeEmoji, constants

    bot.set_message_reaction(message.chat.id, message.id, [ReactionTypeEmoji(constants.ReactionEmoji.ALIEN_MONSTER)], is_big=False)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search