Search code examples
pythonpython-3.xtelegramtelegram-bottelepot

Trying to make a list of chat_id


I'm trying to make a list of chat_id for my Telegram bot that will allow my bot to send one message to all of the chat_id in the list. Here is what I tried,

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

But I'm getting this error

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

So what is wrong here and how to fix this problem ?


Solution

  • chat_id parameter of semdMessage method should be int, not list or other iterable.

    If you wish to send same text message to multiple recipients, do it in a loop:

    listofids = [191929390, 102938483]  # int here
    
    for recipient_id in listofids:
        bot.sendMessage(recipient_id, "worked")  # no str() needed