mirror of
https://github.com/Penguin-71630/meme-bot-frontend-dc.git
synced 2026-03-12 20:40:16 +08:00
init DiscordGo
This commit is contained in:
48
main.go
Normal file
48
main.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/Penguin-71630/meme-bot-frontend-dc/bot"
|
||||
"github.com/Penguin-71630/meme-bot-frontend-dc/config"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load environment variables
|
||||
if err := godotenv.Load(); err != nil {
|
||||
log.Println("No .env file found, using system environment variables")
|
||||
}
|
||||
|
||||
// Load configuration
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load configuration: %v", err)
|
||||
}
|
||||
|
||||
// Initialize bot
|
||||
discordBot, err := bot.New(cfg)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create bot: %v", err)
|
||||
}
|
||||
|
||||
// Start bot
|
||||
if err := discordBot.Start(); err != nil {
|
||||
log.Fatalf("Failed to start bot: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("Bot is now running. Press CTRL-C to exit.")
|
||||
|
||||
// Wait for interrupt signal
|
||||
sc := make(chan os.Signal, 1)
|
||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||
<-sc
|
||||
|
||||
// Cleanup
|
||||
discordBot.Stop()
|
||||
fmt.Println("Bot stopped gracefully.")
|
||||
}
|
||||
Reference in New Issue
Block a user