From 79473f4b33ae438007d49370e4b937d66537c2f9 Mon Sep 17 00:00:00 2001 From: xy Date: Mon, 19 Feb 2024 11:43:44 +0900 Subject: [PATCH] Check for .env file before loading 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. --- src/bin/bootstrap.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bin/bootstrap.rs b/src/bin/bootstrap.rs index 4bef0e9..6da6306 100644 --- a/src/bin/bootstrap.rs +++ b/src/bin/bootstrap.rs @@ -1,5 +1,6 @@ use serenity::{client::Client, prelude::*}; use std::env; +use std::path::Path; use tokio; use dotenv; @@ -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");