繁体   English   中英

Python 3.X 和电报机器人 5.6 消息转发不起作用

[英]Python 3.X and telegram-bot 5.6 message forwarding is not working

场景:我正在编写一个机器人来将几个选定的消息从私人频道传输给这个人(我有他/她的我)或我有它的 id 的另一个组

地位:

  • Bot:我的私人频道的管理员。(来自部分或来源):(id=-15XXXXXX)

  • 机器人:隐私模式已关闭

  • Bot:转发到组的普通成员(到部分或接收器)(我也有 id)

  • 我:私人频道的管理员

  • 我:普通会员

  • 用户:我有他/她的电报 ID(我也有这个 ID)

以下是转发 function 的代码

    def forwardMsg(self, update: Update, context: CallbackContext):
            context.bot.forwardMessage(chat_id=update.effective_chat.id, 
            from_chat_id=-15XXXXXX, message_id=4463)

以下是我的主要代码

    forwardMsg_handler = CommandHandler('forwardMsg', forwardMsg)
    dispatcher.add_handler(forwardMsg_handler)

所有其他命令都在工作。

我在 Pycharm 控制台中收到以下错误

telegram.error.BadRequest: Chat not found

我到处搜索,它必须工作,但它没有。 为什么?

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:\ProgramData\Anaconda3\envs\pythonProject\lib\site- 
packages\telegram\ext\dispatcher.py", line 555, in process_update
handler.handle_update(update, self, check, context)
File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site- 
packages\telegram\ext\handler.py", line 198, in handle_update
return self.callback(update, context)
File "C:\Users\a\PycharmProjects\telegramBot\commands\bot_commands.py", line 70, in 
forwardMsg
context.bot.forwardMessage(chat_id=update.effective_chat.id, from_chat_id=-154*****, 
message_id=4463)
File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\telegram\bot.py", 
line 130, in decorator
result = func(*args, **kwargs)
File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\telegram\bot.py", 
line 641, in forward_message
protect_content=protect_content,
File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site- 
packages\telegram\ext\extbot.py", line 209, in _message
protect_content=protect_content,
File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\telegram\bot.py", 
line 336, in _message
result = self._post(endpoint, data, timeout=timeout, api_kwargs=api_kwargs)
File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site-packages\telegram\bot.py", 
line 296, in _post
f'{self.base_url}/{endpoint}', data=data, timeout=effective_timeout
File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site- 
packages\telegram\utils\request.py", line 366, in post
**urlopen_kwargs,
File "C:\ProgramData\Anaconda3\envs\pythonProject\lib\site- 
packages\telegram\utils\request.py", line 279, in _request_wrapper
raise BadRequest(message)

telegram.error.BadRequest: Chat not found

在电报机器人问题中也提出了问题here

正如已在此 GitHub 线程上回答的那样,您应该仔细检查通道 ID,因为通道 ID 以 -100 开头。

请等待一段合理的时间,然后再在不同的地方提出相同的问题,并始终在两个线程上表明您也在其他地方提出过该问题。

基于 CallmeStag 输入,我在开头找不到任何 -100

因此,解决方案是 -100 + 从复制帖子链接中获取的频道 ID,作为 from_chat_id 的 integer

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM