mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +00:00
Add ability to delete messages on channels and supergroups
This commit is contained in:
parent
c66b4d4ae3
commit
2911a64772
@ -1240,6 +1240,7 @@ class Client:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def delete_messages(self,
|
def delete_messages(self,
|
||||||
|
chat_id: int or str,
|
||||||
message_ids: list,
|
message_ids: list,
|
||||||
revoke: bool = None):
|
revoke: bool = None):
|
||||||
"""Use this method to delete messages, including service messages, with the following limitations:
|
"""Use this method to delete messages, including service messages, with the following limitations:
|
||||||
@ -1251,15 +1252,32 @@ class Client:
|
|||||||
- If the user has *can_delete_messages* permission in a supergroup or a channel, it can delete any message there.
|
- If the user has *can_delete_messages* permission in a supergroup or a channel, it can delete any message there.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
chat_id (:obj:`int` or :obj:`str`):
|
||||||
|
Unique identifier for the target chat or username of the target channel/supergroup
|
||||||
|
(in the format @username). For your personal cloud storage (Saved Messages) you can
|
||||||
|
simply use "me" or "self".
|
||||||
|
|
||||||
message_ids (:obj:`list`):
|
message_ids (:obj:`list`):
|
||||||
List of identifiers of the messages to delete.
|
List of identifiers of the messages to delete.
|
||||||
|
|
||||||
revoke (:obj:`bool`, optional):
|
revoke (:obj:`bool`, optional):
|
||||||
Deletes messages on both parts (for private chats).
|
Deletes messages on both parts.
|
||||||
|
This is only for private cloud chats and normal groups, messages on
|
||||||
|
channels and supergroups are always revoked (i.e.: deleted for everyone).
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
:class:`pyrogram.Error`
|
:class:`pyrogram.Error`
|
||||||
"""
|
"""
|
||||||
|
peer = self.resolve_peer(chat_id)
|
||||||
|
|
||||||
|
if isinstance(peer, types.InputPeerChannel):
|
||||||
|
return self.send(
|
||||||
|
functions.channels.DeleteMessages(
|
||||||
|
channel=peer,
|
||||||
|
id=message_ids
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
# TODO: Maybe "revoke" is superfluous.
|
# TODO: Maybe "revoke" is superfluous.
|
||||||
# If I want to delete a message, chances are I want it to
|
# If I want to delete a message, chances are I want it to
|
||||||
# be deleted even from the other side
|
# be deleted even from the other side
|
||||||
|
Loading…
x
Reference in New Issue
Block a user