|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +# This is a simple bot using message reactions (emoji) |
| 4 | +# https://core.telegram.org/bots/api#reactiontype |
| 5 | +# https://core.telegram.org/bots/api#update |
| 6 | +# allowed_updates: Specify an empty list to receive all update types except, chat_member, message_reaction, and message_reaction_count. |
| 7 | +# If you want to receive message_reaction events, you cannot simply leave the allowed_updates=None default value. |
| 8 | +# The default list of events does not include chat_member, message_reaction, and message_reaction_count events. |
| 9 | +# You must explicitly specify all the events you wish to receive and add message_reaction to this list. |
| 10 | +# It’s also important to note that after using allowed_updates=[...], in the future, using allowed_updates=None will mean |
| 11 | +# that the list of events you will receive will consist of the events you last explicitly specified. |
| 12 | + |
| 13 | +import random |
| 14 | +from telebot.async_telebot import AsyncTeleBot |
| 15 | +from telebot.types import ReactionTypeEmoji |
| 16 | + |
| 17 | +API_TOKEN = '<api_token>' |
| 18 | +bot = AsyncTeleBot(API_TOKEN) |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +# Send a reactions to all messages with content_type 'text' (content_types defaults to ['text']) |
| 23 | +@bot.message_handler(func=lambda message: True) |
| 24 | +async def send_reaction(message): |
| 25 | + emo = ["\U0001F525", "\U0001F917", "\U0001F60E"] # or use ["🔥", "🤗", "😎"] |
| 26 | + await bot.set_message_reaction(message.chat.id, message.id, [ReactionTypeEmoji(random.choice(emo))], is_big=False) |
| 27 | + |
| 28 | + |
| 29 | +@bot.message_reaction_handler(func=lambda message: True) |
| 30 | +async def get_reactions(message): |
| 31 | + await 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]}") |
| 32 | + |
| 33 | + |
| 34 | +import asyncio |
| 35 | +asyncio.run(bot.infinity_polling(allowed_updates=['message', 'message_reaction'])) |
0 commit comments