正在尝试列出聊天室id

2024-06-07 03:10:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试为我的telegrambot创建一个chat_id列表,它将允许我的bot向列表中的所有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'})

那么这里出了什么问题,如何解决这个问题呢?你知道吗


Tags: id消息列表requestbot错误chatnot
1条回答
网友
1楼 · 发布于 2024-06-07 03:10:46

semdMessage方法的chat_id参数应该是int,而不是list或其他iterable。你知道吗

如果要向多个收件人发送同一条短信,请循环执行:

listofids = [191929390, 102938483]  # int here

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

相关问题 更多 >