Skip to content

disgoorg/paginator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference Go Report Go Version License Paginator Version DisGo Discord

Paginator

Paginator is a simple embed pagination library for DisGo using buttons. It supports both interactions and normal messages.

Getting Started

Installation

$ go get github.com/disgoorg/paginator

Usage

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),
)

Interactions

// 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)

Normal Messages

// 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

Documentation is wip and can be found under

  • Go Reference

Examples

You can find examples here

Troubleshooting

For help feel free to open an issue or reach out on Discord

Contributing

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.

License

Distributed under the License. See LICENSE for more information.

Releases

No releases published

Languages