diff --git a/src/event_handler/handler.rs b/src/event_handler/handler.rs index ab16fe7..ac4a16a 100644 --- a/src/event_handler/handler.rs +++ b/src/event_handler/handler.rs @@ -56,12 +56,10 @@ pub async fn event_handler( && msg.contains("damn") && msg.contains("mains") { - let mentions = data.poise_mentions.load(Ordering::SeqCst) + 1; - data.poise_mentions.store(mentions, Ordering::SeqCst); + data.poise_mentions.fetch_add(1, Ordering::SeqCst); new_message.reply(ctx, "Any last words?").await?; } else if msg.contains("hutao") || msg.contains("hu tao") { - let mentions = data.poise_mentions.load(Ordering::SeqCst) + 1; - data.poise_mentions.store(mentions, Ordering::SeqCst); + let mentions = data.poise_mentions.fetch_add(1, Ordering::SeqCst); new_message .reply(ctx, format!("Hu Tao has been mentioned {} times", mentions)) .await?; diff --git a/src/main.rs b/src/main.rs index d08b48e..41d69fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -195,7 +195,7 @@ async fn main() { Box::pin(async move { poise::builtins::register_globally(ctx, &framework.options().commands).await?; Ok(Data { - poise_mentions: AtomicU32::new(0), + poise_mentions: AtomicU32::new(1), // It's better to clone the bot user once when it starts rather than do http // requests for the serenity::CurrentUser on every comman invocation. bot_user: Arc::from(ready.user.clone()),