如何使用Telebot库通过@link获取群组详细信息



我想创建一个在频道/组上发布消息的机器人,用户发送组地址,例如:@group_name,我需要获得ID、title我在telebot图书馆工作

@bot.message_handler(commands=['addgroup'])
def add_group(message):
msg = bot.send_message(message.chat.id, 'Send group link without @')
bot.register_next_step_handler(msg, add)
def add(message):
url = "telegram.me/" + message.text
keyboard = types.InlineKeyboardMarkup()
keyboard.add(types.InlineKeyboardButton("##HERE I NEED GROUP NAME##", url=url))
msg = bot.send_message(message.chat.id, "Add this group?", reply_markup=keyboard)
bot.register_next_step_handler(msg, check_group)
....

我怎样才能得到这些信息?

让我们阅读电报文档。。。

getChat

使用此方法可以获取有关聊天的最新信息(一对一对话的用户的当前名称、用户、组或频道的当前用户名等(。成功时返回聊天对象。

参数:chat_id-目标聊天的唯一标识符或目标超级组或频道的用户名(格式为@channelusername(。

所以,

chat = bot.get_chat('@username')

第页。S.:register_next_step_handler是反模式,请改用aiogram的FSM。

最新更新