aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorWilliam Hergès <anhgelus@anhgelus.world>2025-07-20 15:51:15 +0200
committerWilliam Hergès <anhgelus@anhgelus.world>2025-07-20 15:51:15 +0200
commit977c818328c1c14880029510c6b3742a12858dcb (patch)
treecec7a6ad988f2ccfe10e7867b7ba821fb633a687 /main.go
parent32c9c22b1468511cfeb38adef17aad4f1120425e (diff)
feat(config): load .env file for default cli values
Diffstat (limited to 'main.go')
-rw-r--r--main.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/main.go b/main.go
index 91b7d9d..4610bc4 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,7 @@ package main
import (
_ "embed"
+ "errors"
"flag"
"github.com/anhgelus/gokord"
"github.com/anhgelus/gokord/utils"
@@ -9,6 +10,8 @@ import (
"github.com/anhgelus/les-copaings-bot/config"
"github.com/anhgelus/les-copaings-bot/user"
"github.com/bwmarrin/discordgo"
+ "github.com/joho/godotenv"
+ "os"
"time"
)
@@ -26,7 +29,11 @@ var (
)
func init() {
- flag.StringVar(&token, "token", "", "token of the bot")
+ err := godotenv.Load()
+ if err != nil && !errors.Is(err, os.ErrNotExist) {
+ utils.SendWarn("Error while loading .env file", "error", err.Error())
+ }
+ flag.StringVar(&token, "token", os.Getenv("TOKEN"), "token of the bot")
}
func main() {