我的电报用户机器人可以私下转发消息,但不能在超级组中转发
My telegram userbot can forward a message in private but not in a supergroup
我正在写一个与电报中的用户机器人相关的小项目。我在尝试将消息从超级组转发给另一个用户时遇到了问题,但是当我尝试从常规聊天中转发消息时,一切都成功了。
库: 热解图
版本:1.4.8
我的代码:
@app.on_message(filters.group & filters.text)
async def formessage(client, message):
text = message.text.lower()
# other code
await message.forward(botdata["id"])
我也试过使用函数:app.forward_messages(botdata["id"], message.chat.id, message.message_id)
但是,唉,我得到了同样的错误
超级组中有新消息时出现的错误:
Traceback (most recent call last):
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 121, in resolve_peer
return await self.storage.get_peer_by_id(peer_id)
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\storage\sqlite_storage.py", line 147, in get_peer_by_id
raise KeyError(f"ID not found: {peer_id}")
KeyError: 'ID not found: 5279709634'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\dispatcher.py", line 222, in handler_worker
await handler.callback(self.client, *args)
File "C:\Users\nyansterowo\Desktop\tg\src\UserBot.py", line 43, in formessage
await message.forward(botdata["id"])
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\types\messages_and_media\message.py", line 2924, in forward
return await self._client.forward_messages(
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\messages\forward_messages.py", line 83, in forward_messages
to_peer=await self.resolve_peer(chat_id),
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 123, in resolve_peer
raise PeerIdInvalid
pyrogram.errors.exceptions.bad_request_400.PeerIdInvalid: Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it
让我再次提醒您,我正在写自拍而不是机器人。我可以很容易地通过电报客户端本身将群组中的消息转发给某人,但是我不能通过代码做到这一点。
首先,你得到的错误是明确的。您的 userbot 的 Session 尚未遇到该组,无法根据其 ID 识别它。您必须首先从该实体接收任何类型的更新。
请参阅此常见问题条目:https://docs.pyrogram.org/faq/peer-id-invalid-error
其次,您尝试转发的群组可能在其群组设置中限制了转发。既然可以通过官方客户端转发,应该不是这样的。
我正在写一个与电报中的用户机器人相关的小项目。我在尝试将消息从超级组转发给另一个用户时遇到了问题,但是当我尝试从常规聊天中转发消息时,一切都成功了。
库: 热解图
版本:1.4.8
我的代码:
@app.on_message(filters.group & filters.text)
async def formessage(client, message):
text = message.text.lower()
# other code
await message.forward(botdata["id"])
我也试过使用函数:app.forward_messages(botdata["id"], message.chat.id, message.message_id)
但是,唉,我得到了同样的错误
超级组中有新消息时出现的错误:
Traceback (most recent call last):
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 121, in resolve_peer
return await self.storage.get_peer_by_id(peer_id)
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\storage\sqlite_storage.py", line 147, in get_peer_by_id
raise KeyError(f"ID not found: {peer_id}")
KeyError: 'ID not found: 5279709634'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\dispatcher.py", line 222, in handler_worker
await handler.callback(self.client, *args)
File "C:\Users\nyansterowo\Desktop\tg\src\UserBot.py", line 43, in formessage
await message.forward(botdata["id"])
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\types\messages_and_media\message.py", line 2924, in forward
return await self._client.forward_messages(
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\messages\forward_messages.py", line 83, in forward_messages
to_peer=await self.resolve_peer(chat_id),
File "C:\Users\nyansterowo\AppData\Local\Programs\Python\Python310\lib\site-packages\pyrogram\methods\advanced\resolve_peer.py", line 123, in resolve_peer
raise PeerIdInvalid
pyrogram.errors.exceptions.bad_request_400.PeerIdInvalid: Telegram says: [400 PEER_ID_INVALID] - The peer id being used is invalid or not known yet. Make sure you meet the peer before interacting with it
让我再次提醒您,我正在写自拍而不是机器人。我可以很容易地通过电报客户端本身将群组中的消息转发给某人,但是我不能通过代码做到这一点。
首先,你得到的错误是明确的。您的 userbot 的 Session 尚未遇到该组,无法根据其 ID 识别它。您必须首先从该实体接收任何类型的更新。
请参阅此常见问题条目:https://docs.pyrogram.org/faq/peer-id-invalid-error
其次,您尝试转发的群组可能在其群组设置中限制了转发。既然可以通过官方客户端转发,应该不是这样的。