Skip to content

feat: add bulk delete command for removing user messages in a channel #83

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

Merged
merged 2 commits into from
Jan 11, 2025
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
46 changes: 46 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1356,6 +1356,52 @@ async def mute(ctx, member: discord.Member, *, reason=None):
)


@bot.slash_command(
guild_only=True,
name="bulkdelete",
description="Removes all messages from a user in a channel",
)
@discord.default_permissions(manage_messages=True, )
async def bulkdelete(ctx, channel: discord.TextChannel, member: discord.Member, *, reason=None):
await SendMetric("builkdelete")
guild = ctx.guild

if reason == None:
reason = await GetTranslatedText(ctx.guild.id,
"punishment_default_reason")


await ctx.defer()
msgcount = 0
try:
# delete msg on channel from user
async for message in channel.history():
if message.author == member:
msgcount+=1
await message.delete()
except Exception as e:
await ctx.respond(
embed=ErrorEmbed(await GetTranslatedText(ctx.guild.id, "error_no_permission")),
ephemeral=True,
)
return

embed = discord.Embed(
title=await GetTranslatedText(ctx.guild.id,
"bulkdelete_title",
CHANNEL=channel,
MEMBER=filterMember(member)),
description=await GetTranslatedText(ctx.guild.id,
"bulkdelete_description",
CHANNEL=channel,
AMOUNT=msgcount,
MEMBER=filterMember(member),
REASON=reason),
colour=discord.Colour.red(),
)
await ctx.respond(embed=embed)


# description="Unmutes a specified user."
@bot.slash_command(
guild_only=True,
3 changes: 3 additions & 0 deletions langs/cat.json
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
"footer_executed_by": "Hammer | Comanda executada per {USERNAME}",
"hello_command": "El Hammer ha tornat!",
"error_deliver_msg": "No s'ha pogut lliurar el missatge a l'usuari {USERNAME}\n Això pot ser a causa que l'usuari sigui un bot, hagi bloquejat el bot o hagi desactivat els missatges directes. \n\n**Però l'usuari ha estat advertit** i s'ha guardat a la meva inoblidable base de dades.",
"error_no_permission": "No tinc els permisos suficients per fer això :( :hammer:",
"automod_warn_title": "{USERNAME} ha estat advertit! :hammer_pick:",
"automod_warn_description": "L'usuari {USERNAME} ha estat advertit perquè ha dit una paraula obscena prohibida",
"automod_warn_footer": "Hammer | Servei d'AutoMod",
@@ -68,6 +69,8 @@
"setdelay_title": "Retard {M} a #{CHANNEL} :hammer_pick:",
"for": "per ",
"setdelay_description": "Aquest canal té ara un retard de **{SECONDS}** segons {REASON}",
"bulkdelete_title": "Eliminació massiva a #{CHANNEL} de @{MEMBER} :hammer_pick:",
"bulkdelete_description": "Tots els missatges de l'usuari @{MEMBER} han estat eliminats, hi havien {AMOUNT} missatges al canal #{CHANNEL}",
"mute_title": "Usuari Silenciat: {MEMBER}",
"mute_description": "L'usuari {MENTION} ha estat silenciat per {REASON}",
"mute_msg": ":no_entry: Has estat silenciat de: {GUILD} per {REASON}",
3 changes: 3 additions & 0 deletions langs/en.json
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
"footer_executed_by": "Hammer | Command executed by {USERNAME}",
"hello_command": "Hammer is back!",
"error_deliver_msg": "Could not deliver the message to the user {USERNAME}\n This may be caused because the user is a bot, has blocked me or has the DMs turned off. \n\n**But the user is warned** and I have saved it into my beautiful unforgettable database",
"error_no_permission": "I don't have enough permission to do that :( :hammer:",
"automod_warn_title": "{USERNAME} has been warned! :hammer_pick:",
"automod_warn_description": "The user {USERNAME} has been warned because said a banned swear word",
"automod_warn_footer": "Hammer | Automod service",
@@ -68,6 +69,8 @@
"setdelay_title": "Delay {M} on #{CHANNEL} :hammer_pick:",
"for": "for ",
"setdelay_description": "This channel now has a delay of **{SECONDS}** seconds {REASON}",
"bulkdelete_title": "Bulk delete in #{CHANNEL} of @{MEMBER} :hammer_pick:",
"bulkdelete_description": "All messages from user @{MEMBER} have been deleted, there were {AMOUNT} messages in the channel #{CHANNEL}",
"mute_title": "User Muted: {MEMBER}",
"mute_description": "User {MENTION} has been muted for {REASON}",
"mute_msg": ":no_entry: You have been muted from: {GUILD} for {REASON}",
3 changes: 3 additions & 0 deletions langs/es.json
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
"footer_executed_by": "Hammer | Comando ejecutado por {USERNAME}",
"hello_command": "¡Hammer ha vuelto!",
"error_deliver_msg": "No se pudo entregar el mensaje al usuario {USERNAME}\n Esto puede deberse a que el usuario es un bot, me ha bloqueado o ha desactivado los MD. \n\n**Pero el usuario ha sido advertido** y lo he guardado en mi inolvidable y hermosa base de datos",
"error_no_permission": "No tengo suficientes permisos para hacer eso :( :hammer:",
"automod_warn_title": "¡{USERNAME} ha sido advertido! :hammer_pick:",
"automod_warn_description": "El usuario {USERNAME} ha sido advertido por haber dicho una palabra prohibida",
"automod_warn_footer": "Hammer | Servicio de AutoMod",
@@ -68,6 +69,8 @@
"setdelay_title": "Retraso {M} en #{CHANNEL} :hammer_pick:",
"for": "por ",
"setdelay_description": "Este canal ahora tiene un retraso de **{SECONDS}** segundos por {REASON}",
"bulkdelete_title": "Eliminación masiva en #{CHANNEL} de @{MEMBER} :hammer_pick:",
"bulkdelete_description": "Todos los mensajes del usuario @{MEMBER} han sido eliminados, había {AMOUNT} mensajes en el canal #{CHANNEL}",
"mute_title": "Usuario Silenciado: {MEMBER}",
"mute_description": "El usuario {MENTION} ha sido silenciado por {REASON}",
"mute_msg": ":no_entry: Has sido silenciado de: {GUILD} por {REASON}",
3 changes: 3 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -84,6 +84,9 @@ def jsonToDict(filename):
"modified",
"removed",
"setdelay_title",
"bulkdelete_title",
"bulkdelete_description",
"error_no_permission",
"for",
"setdelay_description",
"mute_title",