#I can't get the purge function to work
1 messages · Page 1 of 1 (latest)
Hey! Once your issue is solved, press the button below to close this thread!
It looks like it's working, it just couldn't do the whole amount at once
also, make your number option type an Int instead of a string, makes more sense
I actually ran into the same thing recently, cleaning up after #1178267536253521920
I had to run the purge seven or eight times to get it all
It'd be nice if we handled it better
ok so what should I do ?
uh weird my /clear command never did this: https://github.com/BTE-France/BTE-France-Bot/blob/master/cogs/random_commands.py#L42-L77
BTE-France/BTE-France-Bot
@interactions.slash_command(name="clear")
@interactions.slash_default_member_permission(interactions.Permissions.MANAGE_MESSAGES)
@interactions.slash_option(
name="number",
description="Nombre de messages à supprimer",
opt_type=interactions.OptionType.INTEGER,
min_value=1,
max_value=100,
)
async def clear(self, ctx: interactions.SlashContext, number: int = 1):
"Supprimer les x derniers messages"
messages = await ctx.channel.history(limit=number).flatten()
after = messages[-1].id
number = len(messages)
await self._clear(ctx, number, after)
@interactions.message_context_menu(name="Supprimer messages après")
@interactions.slash_default_member_permission(interactions.Permissions.MANAGE_MESSAGES)
async def clear_after(self, ctx: interactions.ContextMenuContext):
after = ctx.target_id
messages = await ctx.channel.history(limit=99, after=after).flatten()
number = len(messages) + 1
await self._clear(ctx, number, after)
async def _clear(
self,
ctx: interactions.SlashContext | interactions.ContextMenuContext,
number: int,
after: interactions.Snowflake,
):
n = await ctx.channel.purge(deletion_limit=number) # n = actual number of messages deleted
if n == number:
return await ctx.send(
embeds=create_info_embed(f"✅ Tu as supprimé les {n} dernier(s) message(s)!"),
ephemeral=True,
)