Scenario: I am writing a bot to transfer couple of selected messages from a private channel to the person(which I have his/her I) or to another group that I have its id
Status:
-
Bot: Admin of my private channel.(from part or source): (id=-15XXXXXX)
-
Bot: Privacy mode is off
-
Bot: normal member of forwarding to group (to part or sink) (I have the id as well)
-
me: Admin of private channel
-
me: normal member
-
user: I have his/her telegram id (I have the id as well)
Following is the code of forward function
def forwardMsg(self, update: Update, context: CallbackContext):
context.bot.forwardMessage(chat_id=update.effective_chat.id,
from_chat_id=-15XXXXXX, message_id=4463)
Following is my main code
forwardMsg_handler = CommandHandler('forwardMsg', forwardMsg)
dispatcher.add_handler(forwardMsg_handler)
All other commands are working.
I get following error in Pycharm console
telegram.error.BadRequest: Chat not found
I searched everywhere, It must work but it doesn’t. WHY?
2022-01-11 19:24:05,822 - apscheduler.scheduler - INFO - Scheduler started
2022-01-11 19:52:32,661 - telegram.ext.dispatcher - ERROR - No error handlers are
registered, logging exception.
Traceback (most recent call last):
File "C:ProgramDataAnaconda3envspythonProjectlibsite-
packagestelegramextdispatcher.py", line 555, in process_update
handler.handle_update(update, self, check, context)
File "C:ProgramDataAnaconda3envspythonProjectlibsite-
packagestelegramexthandler.py", line 198, in handle_update
return self.callback(update, context)
File "C:UsersaPycharmProjectstelegramBotcommandsbot_commands.py", line 70, in
forwardMsg
context.bot.forwardMessage(chat_id=update.effective_chat.id, from_chat_id=-154*****,
message_id=4463)
File "C:ProgramDataAnaconda3envspythonProjectlibsite-packagestelegrambot.py",
line 130, in decorator
result = func(*args, **kwargs)
File "C:ProgramDataAnaconda3envspythonProjectlibsite-packagestelegrambot.py",
line 641, in forward_message
protect_content=protect_content,
File "C:ProgramDataAnaconda3envspythonProjectlibsite-
packagestelegramextextbot.py", line 209, in _message
protect_content=protect_content,
File "C:ProgramDataAnaconda3envspythonProjectlibsite-packagestelegrambot.py",
line 336, in _message
result = self._post(endpoint, data, timeout=timeout, api_kwargs=api_kwargs)
File "C:ProgramDataAnaconda3envspythonProjectlibsite-packagestelegrambot.py",
line 296, in _post
f'{self.base_url}/{endpoint}', data=data, timeout=effective_timeout
File "C:ProgramDataAnaconda3envspythonProjectlibsite-
packagestelegramutilsrequest.py", line 366, in post
**urlopen_kwargs,
File "C:ProgramDataAnaconda3envspythonProjectlibsite-
packagestelegramutilsrequest.py", line 279, in _request_wrapper
raise BadRequest(message)
telegram.error.BadRequest: Chat not found
Question is also asked in telegram-bot issues here
2
Answers
Base on CallmeStag input, I couldnt find any -100 at the beginning of
Therefore the solution is -100 + channel ID taken from Copy Post Link as an integer for from_chat_id
As already answered on this GitHub thread, you should double check the channel ID as channel IDs start with a -100.
Please wait for a reasonable amount of time before you ask the same question in a different place and always indicate on both threads that you have asked the question also elsewhere.