I want the program to respond in the channel on behalf of the user in the comments to a post in which there is a + sign with the word "lol". I wrote the code, but I get an error: "telethon.errors.rpcerrorlist.MsgIdInvalidError: The message ID used in the peer was invalid (caused by GetDiscussionMessageRequest)" in await client.send_message(event.chat, message="lol", comment_to=event.post)
Namely in event.chat
Here is my code:
@client.on(events.NewMessage(chats= id_tg_chanel))
async def my_event_handler(event):
if '+' in event.raw_text:
await client.send_message(event.chat, message="lol", comment_to=event.post) #error event.chat
await client.disconnect()
client.run_until_disconnected()
I tried to use await event.reply('lol')
instead of send_message
, but then the program tries to respond in the channel itself (Especially since I don't have the rights to write in the channel), and I need it to respond in the comments. I will be very grateful!
event.post
is not the post ID, it's a boolean (which likely gets treated as a 1 and fails). Try using the ID instead:
@client.on(events.NewMessage(chats=id_tg_chanel))
async def my_event_handler(event):
if '+' in event.raw_text:
# respond is the same as `client.send_message(event.chat, ...)`
# but works even if chat is missing
await event.respond("lol", comment_to=event.id)
await client.disconnect()
client.run_until_disconnected()