首页 > 解决方案 > 尝试列出 chat_id

问题描述

我正在尝试chat_id为我的 Telegram 机器人制作一个列表,这将允许我的机器人向列表中的所有人发送一条消息chat_id。这是我尝试过的,

    listofids = ['191929390', '102938483']
    bot.sendMessage(listofids, str("worked"))

但我收到了这个错误

telepot.exception.TelegramError: ('Bad Request: chat not found', 400, {'ok': False, 'error_code': 400, 'description': 'Bad Request: chat not found'})

那么这里有什么问题以及如何解决这个问题?

标签: pythonpython-3.xtelegramtelegram-bottelepot

解决方案


chat_id方法的参数semdMessage应该是int,不是list或其他可迭代的。

如果您希望将相同的短信发送给多个收件人,请循环执行:

listofids = [191929390, 102938483]  # int here

for recipient_id in listofids:
    bot.sendMessage(recipient_id, "worked")  # no str() needed

推荐阅读