我正在做一个机器人主持人。我正在执行“禁止”命令。如果我通过输入 /ban
回复某人的消息,机器人应该获取其 id 并限制他。
我现在的代码:
@bot.messsage_handler(commands=['ban'])
def ban(message):
#here I should get the id of a user which I replied in Telegram
#then bot should restrict him.
PyTelegramBotApi
Python 3.7
谢谢
最佳答案
在Message
类中,您有一个reply_to_message
,它返回一个Message
对象,您可以从该对象中找到用户ID。如果用户没有回复任何消息,则等于None
。这就是您想要的: message.reply_to_message.from_user
如果您想了解更多信息,可以阅读 Telegram bot API或查看types.py在 github 库中。
关于python - 如果消息是回复,机器人应该获取用户的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63557507/