VND.RUSSIA
VND.RUSSIA

Reputation: 21

Python theleton add text to message

I have such a code:

@client.on(events.NewMessage(chats=ID))
async def handler_new_message(event):
    try:
        await client.send_message(ID, event.message)
        print('Сообщение:',event.message)
    except Exception as e:
        print(e)

How can I add my text to the message body? To be for example so

My text: Message that I got from another channel

Upvotes: 0

Views: 361

Answers (1)

Amir Aref
Amir Aref

Reputation: 401

The event.message object is a string, put it in a variable and add the text you want to it Now put this variable to the send_message function

@client.on(events.NewMessage(chats=ID))
async def handler_new_message(event):
    try:
        message = event.message
        message += ": Message that I got from another channel"
        await client.send_message(ID, message)
        print('Сообщение:',event.message)
    except Exception as e:
        print(e)

Upvotes: 2

Related Questions