#4462·Telethon

NewMessageListener - fired multiple times

Author: rush0815Created Sep 11, 2024Updated Feb 24, 2025

Code that causes the issue

´´'from telethon import TelegramClient, events, sync

api_id = "yyyyy" api_hash = "xxxxxxx" client = TelegramClient('me', api_id, api_hash) clientCommander = TelegramClient('commander', api_id, api_hash)

@client.on(events.NewMessage(chats = inputCmdChannel)) async def NewMessageListener(event): msg = event.message.message

´´´

Expected behavior

I expected, that this function will only be fired once per received new message. So, if the inputCmdChannel has already messages in it and I start the python program, nothing should happen until I send a new message.

Actual behavior

Currently NewMessageListener sometime is fired multiple times and process one or two older messages that are allready in the inputCmdChannel.

Traceback

No response

Telethon version

36.0

Python version

3.10.12

Operating system (including distribution name and version)

Debian 12.2

Other details

No response

Checklist

  • The error is in the library's code, and not in my own.
  • I have searched for this issue before posting it and there isn't an open duplicate.
  • I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.