Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reason to delete_messages, fixes #1252 #1253

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add reason to delete_messages, fixes #1252
  • Loading branch information
jab416171 committed Apr 11, 2022
commit d725a3e5fef0bcb9409ab46e8daf6335a4984594
8 changes: 5 additions & 3 deletions discord/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def permissions_for(self, obj: Union[Member, Role], /) -> Permissions:
raise ClientException("Parent channel not found")
return parent.permissions_for(obj)

async def delete_messages(self, messages: Iterable[Snowflake]) -> None:
async def delete_messages(self, messages: Iterable[Snowflake], *, reason: Optional[str] = None) -> None:
"""|coro|

Deletes a list of messages. This is similar to :meth:`Message.delete`
Expand All @@ -373,6 +373,8 @@ async def delete_messages(self, messages: Iterable[Snowflake]) -> None:
-----------
messages: Iterable[:class:`abc.Snowflake`]
An iterable of messages denoting which ones to bulk delete.
reason: Optional[:class:`str`]
The reason for deleting the messages. Shows up on the audit log.

Raises
------
Expand All @@ -394,14 +396,14 @@ async def delete_messages(self, messages: Iterable[Snowflake]) -> None:

if len(messages) == 1:
message_id = messages[0].id
await self._state.http.delete_message(self.id, message_id)
await self._state.http.delete_message(self.id, message_id, reason=reason)
return

if len(messages) > 100:
raise ClientException("Can only bulk delete messages up to 100 messages")

message_ids: SnowflakeList = [m.id for m in messages]
await self._state.http.delete_messages(self.id, message_ids)
await self._state.http.delete_messages(self.id, message_ids, reason=reason)

async def purge(
self,
Expand Down