2025-09-14 18:54:56 -04:00
|
|
|
import discord
|
|
|
|
|
from discord import app_commands
|
|
|
|
|
from discord.ext import commands
|
|
|
|
|
from discord.ext.commands import Context
|
|
|
|
|
|
2025-11-02 23:32:52 -05:00
|
|
|
|
2025-09-28 23:07:46 -04:00
|
|
|
def purge_command():
|
2025-09-14 18:54:56 -04:00
|
|
|
@commands.hybrid_command(
|
|
|
|
|
name="purge",
|
|
|
|
|
description="Delete a number of messages.",
|
|
|
|
|
)
|
|
|
|
|
@commands.has_guild_permissions(manage_messages=True)
|
|
|
|
|
@commands.bot_has_permissions(manage_messages=True)
|
2025-10-04 13:22:54 -04:00
|
|
|
@app_commands.describe(
|
|
|
|
|
amount="The amount of messages that should be deleted.",
|
2025-11-02 23:32:52 -05:00
|
|
|
user="The user whose messages should be deleted (optional).",
|
2025-10-04 13:22:54 -04:00
|
|
|
)
|
|
|
|
|
async def purge(self, context, amount: int, user: discord.Member = None):
|
|
|
|
|
if context.interaction:
|
|
|
|
|
await context.defer(ephemeral=True)
|
2025-11-02 23:32:52 -05:00
|
|
|
|
2025-10-04 13:22:54 -04:00
|
|
|
if user:
|
|
|
|
|
deleted_count = 0
|
2025-11-02 23:32:52 -05:00
|
|
|
|
2025-10-04 13:22:54 -04:00
|
|
|
def check(message):
|
|
|
|
|
nonlocal deleted_count
|
|
|
|
|
if message.author == user and deleted_count < amount:
|
|
|
|
|
deleted_count += 1
|
|
|
|
|
return True
|
|
|
|
|
return False
|
2025-11-02 23:32:52 -05:00
|
|
|
|
2025-10-04 13:22:54 -04:00
|
|
|
purged_messages = await context.channel.purge(limit=300, check=check)
|
|
|
|
|
else:
|
|
|
|
|
purged_messages = await context.channel.purge(limit=amount)
|
2025-11-02 23:32:52 -05:00
|
|
|
|
2025-09-14 18:54:56 -04:00
|
|
|
embed = discord.Embed(
|
2025-09-16 06:57:12 -04:00
|
|
|
title="Purge",
|
2025-11-02 23:32:52 -05:00
|
|
|
description=f"**{context.author}** cleared **{len(purged_messages)}** messages!"
|
|
|
|
|
+ (f" from **{user}**" if user else ""),
|
2025-09-16 06:57:12 -04:00
|
|
|
color=0x7289DA,
|
2025-09-14 18:54:56 -04:00
|
|
|
)
|
2025-11-02 23:32:52 -05:00
|
|
|
embed.set_author(
|
|
|
|
|
name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png"
|
|
|
|
|
)
|
|
|
|
|
|
2025-10-04 13:22:54 -04:00
|
|
|
if context.interaction:
|
|
|
|
|
await context.send(embed=embed, ephemeral=True)
|
|
|
|
|
else:
|
|
|
|
|
await context.send(embed=embed, delete_after=10)
|
2025-11-02 23:32:52 -05:00
|
|
|
|
|
|
|
|
return purge
|