为什么观察者看不到chat_id?

问题描述 投票:0回答:1
    async def watcher(self, message: Message):
        if self.config["test"] and message.chat_id == -12346568 and message.sender_id == 7654321 and "test" in message.raw_text:
            await self.client.send_message(self.forum_id, "Test", reply_to=self.topic4_id)

在这种情况下,代码不会读取chat_id中的消息,就好像我指定错误一样

更新: 如果您不指定chat_id,那么一切正常,但这是先决条件

if self.config["test"] and message.sender is not None and message.sender.id == 87654321 and "test" in message.text:
    
    await self.client.send_message(self.forum_id, "Test", reply_to=self.topic4_id)
python telegram telethon telegram-api
1个回答
0
投票

根据Telegram文档,您应该像这样访问聊天ID

message.chat.id
而不是
message.chat_id

这是更正后的代码片段

async def watcher(self, message: Message):
        if self.config["test"] and message.chat.id == -12346568 and message.sender_id == 7654321 and "test" in message.raw_text:
            await self.client.send_message(self.forum_id, "Test", reply_to=self.topic4_id)
© www.soinside.com 2019 - 2024. All rights reserved.