Алексей
Алексей

Reputation: 1

Bot wrongly handle messages

I have little problem with writing my bot, I'm trying to send message only inside my bot, but my client handle any messages in any chats.

from telethon.sync import TelegramClient, events
import socks
api_id = 'my_id'
api_hash = 'my_hash'
client = TelegramClient('name', api_id, api_hash, proxy=###).start(bot_token='bot_token') 

@client.on(events.NewMessage(pattern='/start'))
async def send_welcome(event):
    await event.reply('How re you doing')

@client.on(events.NewMessage)
async def echo_all(event):
    await event.reply(event.text)

client.run_until_disconnected()

Upvotes: 0

Views: 135

Answers (1)

TheKill-996
TheKill-996

Reputation: 1069

You need to had func=lambda e: e.is_private into events.NewMessage() so the handler will only catch messages from private conversations (that's what you defined as "messages only inside your bot").

It will look like this:

@events.register(events.NewMessage(func=lambda e: e.is_private))
async def handler(event):
    ...

Upvotes: 1

Related Questions