oceanic-pagination
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Oceanic Pagination

npm bundle size (scoped) GitHub npm (scoped)

A simple button and reaction pagination library for Oceanic.js

Installation

npm i oceanic-pagination oceanic.js

Usage

Button Pagination

const { ButtonPaginationBuilder } = require('oceanic-pagination');
const { ButtonStyles, Client, ComponentTypes, InteractionTypes } = require('oceanic.js');

const bot = new Client({
    auth: 'Bot TOKEN_HERE',
    gateway: {
        intents: ['GUILDS', 'MESSAGE_CONTENT']
    }
});

bot.on('interactionCreate', async interaction => {
    if (interaction.type === InteractionTypes.APPLICATION_COMMAND && interaction.data.name === 'pagination') {
        // Create pagination
        const pagination = new ButtonPaginationBuilder({
            pages: [
                'Page 1',
                { author: { name: 'Page 2' } },
                { content: 'Page 3', embeds: [{ title: 'Page 3' }] },
                () => ({ author: { name: 'Page 4' } })
            ],
            buttons: [
                {
                    button: { type: ComponentTypes.BUTTON, label: 'First', customID: 'first', style: ButtonStyles.SECONDARY },
                    type: 'FirstPage'
                },
                {
                    button: { type: ComponentTypes.BUTTON, label: 'Previous', customID: 'prev', style: ButtonStyles.PRIMARY },
                    type: 'PreviousPage'
                },
                {
                    button: { type: ComponentTypes.STOP, label: 'Stop', customID: 'stop', style: ButtonStyles.DANGER },
                    type: 'Stop'
                },
                {
                    button: { type: ComponentTypes.BUTTON, label: 'Next', customID: 'next', style: ButtonStyles.PRIMARY },
                    type: 'NextPage'
                },
                {
                    button: { type: ComponentTypes.BUTTON, label: 'Last', customID: 'last', style: ButtonStyles.SECONDARY },
                    type: 'LastPage'
                },
            ]
        });

        // Listens to pagination errors
        pagination.on('error', console.log);

        // Sends the pagination message
        await pagination.send({ command: interaction, sendAs: 'ReplyMessage' });
    }
});

bot.connect();

Reaction Pagination

⚠️ You cannot use reaction pagination with ephemeral messages

const { ReactionPaginationBuilder } = require('oceanic-pagination');
const { Client } = require('oceanic.js');

const bot = new Client({
    auth: 'Bot TOKEN_HERE',
    gateway: {
        intents: ['GUILDS', 'MESSAGE_CONTENT', 'GUILD_MESSAGE_REACTIONS']
    }
});

bot.on('interactionCreate', async interaction => {
    if (interaction.type === InteractionTypes.APPLICATION_COMMAND && interaction.data.name === 'pagination') {
        // Create pagination
        const pagination = new ReactionPaginationBuilder({
            pages: [
                'Page 1',
                { author: { name: 'Page 2' } },
                { content: 'Page 3', embeds: [{ title: 'Page 3' }] },
                () => ({ author: { name: 'Page 4' } })
            ],
            reactions: [
                { emoji: '⏪', type: 'FirstPage' }
                { emoji: '⬅', type: 'PreviousPage' }
                { emoji: '🛑', type: 'Stop' }
                { emoji: '➡️', type: 'NextPage' }
                { emoji: '⏩', type: 'LastPage' }
            ]
        });

        // Listens to pagination errors
        pagination.on('error', console.log);

        // Sends the pagination message
        await pagination.send({ command: interaction, sendAs: 'ReplyMessage' });
    }
});

bot.connect();

Package Sidebar

Install

npm i oceanic-pagination

Weekly Downloads

1

Version

1.0.2

License

none

Unpacked Size

112 kB

Total Files

39

Last publish

Collaborators

  • catplusplus