package main import ( "context" "github.com/disgoorg/disgo" "github.com/disgoorg/disgo/bot" "github.com/disgoorg/disgo/cache" "github.com/disgoorg/disgo/gateway" "github.com/disgoorg/log" "grow.rievo.dev/discordBots/cmd/welcomebot/config" "grow.rievo.dev/discordBots/cmd/welcomebot/event" "os" "os/signal" "syscall" ) func main() { log.SetLevel(log.LevelInfo) log.Info("starting welcomebot...") log.Info("disgo version: ", disgo.Version) // permissions: Manage Roles // intent: Server Members Intent client, err := disgo.New(config.Token, bot.WithGatewayConfigOpts( gateway.WithIntents(gateway.IntentGuildMembers), ), bot.WithCacheConfigOpts( cache.WithCaches( cache.FlagsNone, ), ), bot.WithEventListenerFunc(event.JoinEvent), bot.WithEventListenerFunc(event.LeaveEvent), bot.WithEventListenerFunc(event.ReactionEvent), ) if err != nil { log.Fatal("error while building disgo instance: ", err) return } defer client.Close(context.TODO()) if err = client.OpenGateway(context.TODO()); err != nil { log.Fatal("error while connecting to gateway: ", err) } channels, err := client.Rest().GetGuildChannels(config.RegisterGuildID) for _, channel := range channels { switch channel.Name() { case "🔨-rules": config.ChannelRulesMention = channel.Mention() case "❕-info": config.ChannelInfoMention = channel.Mention() case "👋-welcome": config.ChannelWelcomeID = channel.ID() } } if config.ChannelRulesMention == "" || config.ChannelInfoMention == "" || config.ChannelWelcomeID == 0 { log.Fatal("couldn't find needed channel") } roles, err := client.Rest().GetRoles(config.RegisterGuildID) for _, role := range roles { switch role.Name { case "Apple": config.RoleAppleID = role.ID case "Apple Core": config.RoleAppleCoreID = role.ID } } if config.RoleAppleID == 0 || config.RoleAppleCoreID == 0 { log.Fatal("couldn't find needed role") } log.Infof("welcomebot is now running. Press CTRL-C to exit.") s := make(chan os.Signal, 1) signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt) <-s }