mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-06 01:12:33 -05:00
[Cleanup] Pass reason for bulk message deletion to audit log (#5863)
Co-authored-by: Jakub Kuczys <me@jacken.men>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
from typing import List, Iterable, Union, TYPE_CHECKING, Dict
|
||||
from typing import List, Iterable, Union, TYPE_CHECKING, Dict, Optional
|
||||
|
||||
import discord
|
||||
|
||||
@@ -12,6 +12,8 @@ if TYPE_CHECKING:
|
||||
async def mass_purge(
|
||||
messages: List[discord.Message],
|
||||
channel: Union[discord.TextChannel, discord.VoiceChannel, discord.Thread],
|
||||
*,
|
||||
reason: Optional[str] = None,
|
||||
):
|
||||
"""Bulk delete messages from a channel.
|
||||
|
||||
@@ -29,6 +31,8 @@ async def mass_purge(
|
||||
The messages to bulk delete.
|
||||
channel : `discord.TextChannel`, `discord.VoiceChannel`, or `discord.Thread`
|
||||
The channel to delete messages from.
|
||||
reason : `str`, optional
|
||||
The reason for bulk deletion, which will appear in the audit log.
|
||||
|
||||
Raises
|
||||
------
|
||||
@@ -43,7 +47,7 @@ async def mass_purge(
|
||||
# discord.NotFound can be raised when `len(messages) == 1` and the message does not exist.
|
||||
# As a result of this obscure behavior, this error needs to be caught just in case.
|
||||
try:
|
||||
await channel.delete_messages(messages[:100])
|
||||
await channel.delete_messages(messages[:100], reason=reason)
|
||||
except discord.errors.HTTPException:
|
||||
pass
|
||||
messages = messages[100:]
|
||||
|
||||
Reference in New Issue
Block a user