Paginator is a simple embed pagination library for DisGo using buttons. It supports both interactions and normal messages.
$ go get github.com/disgoorg/paginator
Create a new paginator and add it as EventHandler
to your Client.
manager := paginator.New()
client, err := disgo.New(token,
bot.WithDefaultGateway(),
bot.WithEventListeners(manager),
)
// your data to paginate through
pData := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}
// create a new paginator.Pages
err := manager.Create(event.Respond, paginator.Pages{
// A unique ID for this paginator
ID: event.ID().String(),
// This is the function that will be called to create the embed for each page when the page is displayed
PageFunc: func(page int, embed *discord.EmbedBuilder) {
embed.SetTitle("Data")
description := ""
for i := 0; i < 5; i++ {
if page*5+i >= len(pData) {
break
}
description += pData[page*5+i] + "\n"
}
embed.SetDescription(description)
},
// The total number of pages
Pages: int(math.Ceil(float64(len(pData)) / 5)),
// Optional: If the paginator should only be accessible by the user who created it
Creator: event.User().ID,
// Optional: If the paginator should be deleted after x time after the last interaction
ExpireMode: paginator.ExpireModeAfterLastUsage,
}, false)
// your data to paginate through
pData := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}
channelID := 123454545
// create a new paginator.Pages
err := manager.CreateMessage(event.Client(), channelID, paginator.Pages{
// A unique ID for this paginator
ID: event.Message.ID.String(),
// This is the function that will be called to create the embed for each page when the page is displayed
PageFunc: func(page int, embed *discord.EmbedBuilder) {
embed.SetTitle("Data")
description := ""
for i := 0; i < 5; i++ {
if page*5+i >= len(pData) {
break
}
description += pData[page*5+i] + "\n"
}
embed.SetDescription(description)
},
// The total number of pages
Pages: int(math.Ceil(float64(len(pData)) / 5)),
// Optional: If the paginator should only be accessible by the user who created it
Creator: event.User().ID,
// Optional: If the paginator should be deleted after x time after the last interaction
ExpireMode: paginator.ExpireModeAfterLastUsage,
}, false)
Documentation is wip and can be found under
You can find examples here
For help feel free to open an issue or reach out on Discord
Contributions are welcomed but for bigger changes we recommend first reaching out via Discord or create an issue to discuss your problems, intentions and ideas.