0

I'm trying to create a chatbot that will read the number of reactions and send them to me. In the pyTelegramBotAPI documentation, I found the message_reaction_count_handler and message_reaction_handler methods, but both of them do not work. There is almost no information on the Internet since this is a recent update.

import telebot
from telebot.types import *

TOKEN = 'token'
bot = telebot.TeleBot(TOKEN)


@bot.message_handler(func=lambda message: True)
def message_handler(message):
    bot.send_message(message.chat.id, message.text)

@bot.message_reaction_handler(func=lambda update: True)
async def message_reaction_handler(update: MessageReactionUpdated):
    print("Reaction update received:")
    print(f'Message ID: {update.message_id}')
    for reaction in update.reactions:
        print(f'Reaction: {reaction.type.type}, Count: {reaction.total_count}')

@bot.message_reaction_count_handler(func=lambda update: True)
async def message_reaction_count_handler(update: MessageReactionCountUpdated):
    print("Reaction update received:")
    print(f'Message ID: {update.message_id}')
    for reaction in update.reactions:
        print(f'Reaction: {reaction.type.type}, Count: {reaction.total_count}')



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

The message_handler function is working

2 Answers 2

0

Here is an example of using these functions.

# Send a reactions to all messages with content_type 'text' (content_types defaults to ['text'])
@bot.message_handler(func=lambda message: True)
def send_reaction(message):
    bot.set_message_reaction(message.chat.id, message.id, [telebot.types.ReactionTypeEmoji("🔥")], is_big=False)


@bot.message_reaction_handler(func=lambda message: True)
def get_reactions(message):
    bot.reply_to(message, f"You changed the reaction from {[r.emoji for r in message.old_reaction]} to {[r.emoji for r in message.new_reaction]}")


bot.infinity_polling(allowed_updates=['message', 'message_reaction'])

The bot must be an administrator in the chat and must explicitly specify «message_reaction» in the list of allowed_updates to receive these updates. The update isn’t received for reactions set by bots.

Sign up to request clarification or add additional context in comments.

Comments

0

Telegram at the moment does not send message_reaction updates from individual users in channels (for privacy reasons oddly). It only sends message_reaction_count occasionally.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.