feat(config): load .env file for default cli values

This commit is contained in:
Anhgelus Morhtuuzh 2025-07-20 15:51:15 +02:00
parent 32c9c22b14
commit 977c818328
Signed by: anhgelus
GPG key ID: 617773CACE89052C
3 changed files with 11 additions and 1 deletions

View file

@ -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() {