mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 03:38:53 -05:00
[V3 Cleanup] Cleanup Before command (#2171)
Adds the ability to cleanup before a specified message id. Requires passing a number of messages to delete to keep with syntax of cleanup self/user
This commit is contained in:
parent
a04869ab27
commit
3cb2b95121
@ -221,8 +221,6 @@ class Cleanup(commands.Cog):
|
||||
To get a message id, enable developer mode in Discord's
|
||||
settings, 'appearance' tab. Then right click a message
|
||||
and copy its id.
|
||||
|
||||
This command only works on bots running as bot accounts.
|
||||
"""
|
||||
|
||||
channel = ctx.channel
|
||||
@ -247,6 +245,40 @@ class Cleanup(commands.Cog):
|
||||
|
||||
await mass_purge(to_delete, channel)
|
||||
|
||||
@cleanup.command()
|
||||
@commands.guild_only()
|
||||
async def before(
|
||||
self, ctx: commands.Context, message_id: int, number: int, delete_pinned: bool = False
|
||||
):
|
||||
"""Deletes X messages before specified message.
|
||||
|
||||
To get a message id, enable developer mode in Discord's
|
||||
settings, 'appearance' tab. Then right click a message
|
||||
and copy its id.
|
||||
"""
|
||||
|
||||
channel = ctx.channel
|
||||
if not channel.permissions_for(ctx.guild.me).manage_messages:
|
||||
await ctx.send("I need the Manage Messages permission to do this.")
|
||||
return
|
||||
author = ctx.author
|
||||
|
||||
try:
|
||||
before = await channel.get_message(message_id)
|
||||
except discord.NotFound:
|
||||
return await ctx.send(_("Message not found."))
|
||||
|
||||
to_delete = await self.get_messages_for_deletion(
|
||||
channel=channel, number=number, before=before, delete_pinned=delete_pinned
|
||||
)
|
||||
|
||||
reason = "{}({}) deleted {} messages in channel {}.".format(
|
||||
author.name, author.id, len(to_delete), channel.name
|
||||
)
|
||||
log.info(reason)
|
||||
|
||||
await mass_purge(to_delete, channel)
|
||||
|
||||
@cleanup.command()
|
||||
@commands.guild_only()
|
||||
async def messages(self, ctx: commands.Context, number: int, delete_pinned: bool = False):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user