Skip to content
This repository was archived by the owner on Mar 24, 2024. It is now read-only.

Commit e673e91

Browse files
committed
make command creation return result instead of panicking
1 parent 8f32730 commit e673e91

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/bot/commands/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 ThatsNoMoon
1+
// Copyright 2023 ThatsNoMoon
22
// Licensed under the Open Software License version 3.0
33

44
//! Implementations of all of the explicit bot commands.
@@ -30,7 +30,7 @@ use serenity::{
3030
Permissions,
3131
},
3232
};
33-
use tracing::{debug, info};
33+
use tracing::debug;
3434

3535
pub(crate) use self::{
3636
blocks::{block, blocks, unblock},
@@ -49,8 +49,8 @@ use crate::{
4949
};
5050

5151
// Create all slash commands globally, and in a test guild if configured.
52-
pub(crate) async fn create_commands(ctx: Context) {
53-
info!("Registering slash commands");
52+
pub(crate) async fn create_commands(ctx: Context) -> Result<()> {
53+
debug!("Registering slash commands");
5454
let commands = COMMAND_INFO
5555
.iter()
5656
.map(CommandInfo::create)
@@ -63,13 +63,15 @@ pub(crate) async fn create_commands(ctx: Context) {
6363
create.set_application_commands(commands.clone())
6464
})
6565
.await
66-
.expect("Failed to create guild application commands");
66+
.context("Failed to create guild application commands")?;
6767
}
6868
ApplicationCommand::set_global_application_commands(&ctx, |create| {
6969
create.set_application_commands(commands)
7070
})
7171
.await
72-
.expect("Failed to set global application commands");
72+
.context("Failed to set global application commands")?;
73+
74+
Ok(())
7375
}
7476

7577
/// Display the API latency of the bot.

src/bot/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 ThatsNoMoon
1+
// Copyright 2023 ThatsNoMoon
22
// Licensed under the Open Software License version 3.0
33

44
//! Discord client creation and behavior.
@@ -140,7 +140,9 @@ async fn ready(ctx: Context) {
140140

141141
ctx.set_activity(Activity::listening("/help")).await;
142142

143-
commands::create_commands(ctx).await;
143+
if let Err(e) = commands::create_commands(ctx).await {
144+
error!("{e}\n{e:?}");
145+
}
144146

145147
let _ = STARTED.set(Instant::now());
146148

0 commit comments

Comments
 (0)