DeleteMessagesRequest

Both users and bots can use this request. See code examples.

---functions---
channels.deleteMessages#84c1fd4e channel:InputChannel id:Vector<int> = messages.AffectedMessages

Returns

messages.AffectedMessages

This type can only be an instance of:

AffectedMessages

Parameters

channelInputChannelAnything entity-like will work if the library can find its Input version (e.g., usernames, Peer, User or Channel objects, etc.).
idintA list must be supplied.

Known RPC errors

This request can cause 3 known errors:

ChannelInvalidErrorInvalid channel object. Make sure to pass the right types, for instance making sure that the request is designed for channels or otherwise look for a different one more suited.
ChannelPrivateErrorThe channel specified is private and you lack permission to access it. Another reason may be that you were banned from it.
MessageDeleteForbiddenErrorYou can't delete one of the messages you tried to delete, most likely because it is a service message..

You can import these from telethon.errors.

Example

Please refer to the documentation of client.delete_messages() to learn about the parameters and see several code examples on how to use it.

The method above is the recommended way to do it. If you need more control over the parameters or want to learn how it is implemented, open the details by clicking on the "Details" text.

from telethon.sync import TelegramClient
from telethon import functions, types

with TelegramClient(name, api_id, api_hash) as client:
    result = client(functions.channels.DeleteMessagesRequest(
        channel='username',
        id=[42]
    ))
    print(result.stringify())