1.0.2 • Published 12 months ago

oceanic-pagination v1.0.2

Weekly downloads
-
License
-
Repository
github
Last release
12 months ago

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();
1.0.2

12 months ago

1.0.1

1 year ago

1.0.0

1 year ago