package main import ( "context" "fmt" "github.com/disgoorg/disgo" "github.com/disgoorg/disgo/bot" "github.com/disgoorg/disgo/cache" "github.com/disgoorg/disgo/gateway" "github.com/disgoorg/log" "github.com/disgoorg/snowflake/v2" "os" ) var ( token = os.Getenv("disgo_token") registerGuildID = snowflake.GetEnv("disgo_guild_id") ) func main() { log.SetLevel(log.LevelDebug) log.Info("starting groupbot...") log.Info("disgo version: ", disgo.Version) // permissions: // intent: client, err := disgo.New(token, bot.WithGatewayConfigOpts( gateway.WithIntents(gateway.IntentsNone), ), bot.WithCacheConfigOpts( cache.WithCaches( cache.FlagsNone, ), ), ) if err != nil { log.Fatal("error while building disgo instance: ", err) return } defer client.Close(context.TODO()) var groups Groups for i := 0; i < 30; i++ { groups = append(groups, Group{ name: fmt.Sprintf("g%v", i), group: "", emoji: "", }) } createGroupMessage(groups) if err = client.OpenGateway(context.TODO()); err != nil { log.Fatal("error while connecting to gateway: ", err) } log.Infof("groupbot is now running. Press CTRL-C to exit.") //s := make(chan os.Signal, 1) //signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt) //<-s } type Group struct { name string group string emoji string } type Groups []Group // chunk // source https://github.com/golang/go/issues/53987 func chunk[T any](arrIn []T, size int) (arrOut [][]T) { for i := 0; i < len(arrIn); i += size { end := i + size if end > len(arrIn) { end = len(arrIn) } arrOut = append(arrOut, arrIn[i:end]) } return arrOut } func createGroupMessage(groups Groups) { groupsMessages := chunk(chunk(groups, 5), 5) for _, messageGroups := range groupsMessages { fmt.Println("--- new message ---") for _, rowGroups := range messageGroups { fmt.Printf("new row: ") for _, group := range rowGroups { fmt.Printf("%v;", group.name) } fmt.Println("") } } }