'Telethon: delete a message

I am trying to delete a message using telegram API and Telethon.

Here is my code:

from telethon import InteractiveTelegramClient
from telethon.tl.types.input_peer_channel import InputPeerChannel
from telethon.tl.functions.messages.delete_messages import DeleteMessagesRequest

#...
total_count, messages, senders = client.get_message_history(
                        chat, limit=1)
msg = messages[0]

result = client.invoke(DeleteMessagesRequest([msg.id]))

But first of all nothing happens, and second, it doesn't look right, since msg.id is like 5 or 220 and it doesn't look like a unique number.

Here is the message:

msg: (message (ID: 0xc09bexxx) = (out=None, mentioned=None, media_unread=None, silent=None, post=True, id=5, from_id=None, to_id=(peerChannel (ID: 0xbdddexxx) = (channel_id=1234)), fwd_from=None, via_bot_id=None, reply_to_msg_id=None, date=2017-06-14 14:39:23, message=test33, media=None, reply_markup=None, entities=None, views=1, edit_date=None))

I also tried with the hex number 0xc09bexxx but that gives an exception.

So how can I delete a message in a channel?

So far I looked at this github issue to get started with the delete message. My guess is that maybe the following import is not the right one and I should import the version in the Channels package, which gets a channel id and a message id?

from telethon.tl.functions.messages.delete_messages import DeleteMessagesRequest


Solution 1:[1]

from telethon import TelegramClient

client = TelegramClient('cookie', '123', 'XXX')

id_group = -1001231231231

id_message = 3

await client.delete_messages(entity=id_group, message_ids=[id_message])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1