diff --git a/src/bin/bootstrap.rs b/src/bin/bootstrap.rs index a480101..aab01cf 100644 --- a/src/bin/bootstrap.rs +++ b/src/bin/bootstrap.rs @@ -27,7 +27,7 @@ async fn main() { }; // Create a new client with the discord token - let mut client = create_client( + let client_result = create_client( &get_env( "DISCORD_TOKEN", "Expected a discord token in the environment", @@ -37,6 +37,14 @@ async fn main() { ) .await; + let mut client = match client_result { + Ok(client) => client, + Err(e) => { + error!("Error creating client: {}", e); + return; + } + }; + // Start listening for events info!("Bot is now running. Press Ctrl+C to stop."); if let Err(why) = client.start().await { diff --git a/src/discord/mod.rs b/src/discord/mod.rs index f351690..f905c00 100644 --- a/src/discord/mod.rs +++ b/src/discord/mod.rs @@ -18,9 +18,11 @@ use tracing::{debug, error}; #[derive(Debug, Error)] pub enum Error { #[error(transparent)] - ModelConfigurationBuilderError(#[from] chatgpt::config::ModelConfigurationBuilderError), + ModelConfigurationBuilder(#[from] chatgpt::config::ModelConfigurationBuilderError), #[error(transparent)] ChatGPT(#[from] chatgpt::err::Error), + #[error(transparent)] + Client(#[from] serenity::Error), } type Result = std::result::Result; @@ -143,9 +145,9 @@ pub async fn create_client( discord_token: &str, intents: GatewayIntents, handler: Handler, -) -> Client { - Client::builder(discord_token, intents) +) -> Result { + let ret = Client::builder(discord_token, intents) .event_handler(handler) - .await - .expect("Error creating client") + .await?; + Ok(ret) }