Skip to content

Commit

Permalink
Check for .env file before loading
Browse files Browse the repository at this point in the history
Added a check to ensure .env file exists before loading it to avoid potential errors. This change provides a more robust error-handling mechanism and prevents the application from crashing if the .env file is missing.
  • Loading branch information
kasugamirai committed Feb 19, 2024
1 parent 6e4e07a commit 79473f4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/bin/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serenity::{client::Client, prelude::*};
use std::env;
use std::path::Path;
use tokio;

use dotenv;
Expand All @@ -11,7 +12,9 @@ async fn main() {
// Initialize the logger
env_logger::init();
// Load environment variables from .env file
dotenv::dotenv().expect("Failed to load .env file");
if Path::new(".env").exists() {
dotenv::dotenv().expect("Failed to load .env file");
}
// Get the discord token from the environment
let discord_token =
env::var("DISCORD_TOKEN").expect("Expected a discord token in the environment");
Expand Down

0 comments on commit 79473f4

Please sign in to comment.