Skip to content

Commit

Permalink
Disable allowed mentions on certain errors (serenity-rs#277)
Browse files Browse the repository at this point in the history
Disable allowed mentions on ArgumentParse and Command errors
  • Loading branch information
jamesbt365 committed May 27, 2024
1 parent ecfaa85 commit 6ead1e1
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod paginate;
#[cfg(any(feature = "chrono", feature = "time"))]
pub use paginate::*;

use crate::{serenity_prelude as serenity, CreateReply};
use crate::{serenity::CreateAllowedMentions, serenity_prelude as serenity, CreateReply};

/// An error handler that logs errors either via the [`tracing`] crate or via a Discord message. Set
/// up a logger (e.g. `env_logger::init()`) or a tracing subscriber
Expand Down Expand Up @@ -50,7 +50,18 @@ pub async fn on_error<U, E: std::fmt::Display + std::fmt::Debug>(
crate::FrameworkError::Command { ctx, error } => {
let error = error.to_string();
eprintln!("An error occured in a command: {}", error);
ctx.say(error).await?;

let mentions = CreateAllowedMentions::new()
.everyone(false)
.all_roles(false)
.all_users(false);

ctx.send(
CreateReply::default()
.content(error)
.allowed_mentions(mentions),
)
.await?;
}
crate::FrameworkError::SubcommandRequired { ctx } => {
let subcommands = ctx
Expand Down Expand Up @@ -91,7 +102,18 @@ pub async fn on_error<U, E: std::fmt::Display + std::fmt::Debug>(
} else {
format!("**{}**\n{}", error, usage)
};
ctx.say(response).await?;

let mentions = CreateAllowedMentions::new()
.everyone(false)
.all_roles(false)
.all_users(false);

ctx.send(
CreateReply::default()
.content(response)
.allowed_mentions(mentions),
)
.await?;
}
crate::FrameworkError::CommandStructureMismatch { ctx, description } => {
tracing::error!(
Expand Down

0 comments on commit 6ead1e1

Please sign in to comment.