作为 Telegram 频道的管理员,我如何查看用户对我的帖子的反应

问题描述 投票:0回答:1

我想在电报频道看到会员的反应

我是电报频道的管理员 我已经让用户对我的帖子做出反应 电报不显示哪个用户发送哪个反应 我正在寻找一种方式来查看它 我只希望我作为管理员查看哪个用户对我的帖子发送了哪些反应 例如用户@david 发送了👍

我已经有这个代码但不能用 即使我按机器人的开始和停止也不会发生

import telebot

bot = telebot.TeleBot("YOUR_BOT_TOKEN")

def get_reactions(message):
    for reaction in message.reactions:
        user = reaction.user
        print(f"User {user.username} reacted with {reaction.emoji} to my post.")

bot.polling()

while True:
    for update in bot.get_updates():
        message = update.message
        get_reactions(message)

@bot.message_handler(commands=["start"])
def start(message):
    bot.send_message(message.chat.id, "Code is running")
telegram-bot py-telegram-bot-api
1个回答
0
投票

您的代码有几个问题。首先,最后的

while True
循环会阻塞轮询过程,因此永远不会到达
@bot.message_handler(commands=["start"])
装饰器内的代码。其次,轮询和命令处理程序应该位于同一个块中。

这是代码的改进版本:

    import telebot
    from telebot import types
    
    bot = telebot.TeleBot("YOUR_BOT_TOKEN")
    
    @bot.message_handler(commands=["start"])
    def start(message):
        bot.send_message(message.chat.id, "Code is running")
    
    @bot.message_handler(func=lambda message: True)
    def get_reactions(message):
        if message.reactions:
            for reaction in message.reactions:
                user = reaction.user
                print(f"User {user.username} reacted with {reaction.emoji} to my post.")
    
    # Start polling
    bot.polling(none_stop=True)

在此版本中,轮询位于脚本的主体部分,并且

@bot.message_handler(func=lambda message: True)
装饰器用于处理所有消息。这样,每条消息都会调用
get_reactions
函数,并检查是否有任何反应。

© www.soinside.com 2019 - 2024. All rights reserved.