GithubHelp home page GithubHelp logo

oceanic-pagination's Introduction

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

oceanic-pagination's People

Contributors

notghex avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

dirquel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.