Skip to main content

Overview

The Delete Message command allows moderators to delete any message in Discord channels. This is a context menu command that permanently removes the selected message.
This command requires semester moderator role or MANAGE_MESSAGES permission. Deleted messages cannot be recovered.

Permissions Required

To use this command, you must meet one of these requirements:
  • Be registered in the semestermods database table
  • Have the MANAGE_MESSAGES Discord permission

Usage

  1. Right-click on any message in a channel
  2. Select “Apps” → “Delete Message”
  3. The bot will permanently delete the message

Parameters

message
Message
required
The message to delete (selected via context menu)

Examples

Deleting a Message

Action: Right-click on a message and select “Delete Message” Response:
Deleted message
The message will be permanently removed from the channel.
Deleted messages cannot be recovered. Use this command with caution.

Implementation Details

From moderation.rs:62-73:
#[poise::command(
    context_menu_command = "Delete Message",
    check = "has_mod_or_semestermod",
    guild_only,
    ephemeral
)]
pub async fn delete_message(
    ctx: Context<'_>,
    #[description = "The message to delete"] message: serenity::Message,
) -> Result<(), Error> {
    message
        .delete(&ctx.serenity_context())
        .await
        .map_err(Error::Serenity)?;
    ctx.say("Deleted message").await.map_err(Error::Serenity)?;
    Ok(())
}

Permission Check

The has_mod_or_semestermod function checks:
async fn has_mod_or_semestermod(ctx: Context<'_>) -> Result<bool, Error> {
    let db = &ctx.data().db;
    let member = ctx.author_member().await.unwrap();

    // Check if user is in semestermods table
    let has_perms = sqlx::query("SELECT user_id FROM semestermods WHERE user_id = $1")
        .bind(member.user.id.0 as i64)
        .fetch_optional(db)
        .await
        .map_err(Error::Database)?
        .is_some();

    if has_perms {
        Ok(true)
    } else if member
        .permissions(ctx)
        .map_err(Error::Serenity)?
        .contains(Permissions::MANAGE_MESSAGES)
    {
        return Ok(true);
    } else {
        return Ok(false);
    }
}
The command is ephemeral and guild-only, meaning the response is only visible to the user who invoked it and can only be used in guild channels.

Build docs developers (and LLMs) love