1.0.3 • Published 5 years ago

discordjs-paginator v1.0.3

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

Embed Paginator to use easy and fastly with discord.js

Install

# NPM
$ npm install discordjs-paginator
# Yarn
$ yarn add discordjs-paginator

Options

EmbedPaginator

OptionTypeRequiredDefaultDescription
messageMessageOThe message instance to be binded with paginator
bindPageViewTostring (only "footer" and "author" allowed)xvoidLocation to bind page view like Page: 1 / 3
channelTextChannelxvoidOverrides the message option
emojis.prevstringxThe emoji used for previous button
emojis.stopstringxThe emoji used for stop button
emojis.nextstringxThe emoji used for next button
filterCallbackfunction: booleanx(r, u, e) => r.emoji.name === e && !u.botCallback function to filter reactions
timenumberx360000Timeout to destroy reaction collectors
pageViewstringx"Page: {CURRENT_PAGE} / {TOTAL_PAGE}"Page view text to be binded (only work with bindPageViewTo option)

Usage

If you want to see usage more quickly, click

const { EmbedPaginator } = require("discordjs-paginator")
const { Client, Collection, MessageEmbed } = require("discord.js")
const client = new Client()
const PREFIX = "!"

client.storage = new Collection()
client.deploys = new Collection()

client.on("ready", () => console.log(`Ready as ${client.user.tag}`))

client.on("message", async message => {
    if (
        message.author.bot
        || message.channel.type === "dm"
        || message.system
        || !message.content.startsWith(PREFIX)
    ) return

    const args = message.content.slice(PREFIX.length).trim().split(/ +/gi)
    const command = args.shift().toLowerCase()

    if (command === "embed") {
        const subcommand = args.shift().toLowerCase()

        if (subcommand === "add") {
            const embed = new MessageEmbed().setDescription(args.join(" "))

            const cache = client.storage.get(message.author.id)
            if (cache) client.storage.set(message.author.id, [...cache, embed])
            else client.storage.set(message.author.id, [embed])

            return message.reply("added")
        }
        if (subcommand === "remove") {
            const index = parseInt(args[0]) - 1

            const cache = client.storage.get(message.author.id)
            if (!cache) return message.reply("couldn't find embed to remove, empty storage")
            if (!cache[index]) return message.reply(`index ${index} out of range(length: ${cache.length})`)

            client.storage.set(message.author.id, cache.filter((f, i) => i !== index))
            return message.reply("removed")
        }
        if (subcommand === "deploy") {
            const cache = client.storage.get(message.author.id)
            const msgResolvable = args[0]

            if (!cache) return message.reply("couldn't find embeds to show")
            if (!msgResolvable) return message.reply(`Usage: \`\`${PREFIX}embed deploy <msg ID>\`\``)

            const deploy = new EmbedPaginator({
                message: await message.channel.messages.fetch(msgResolvable),
                bindPageViewTo: "footer",
                pageView: "Page {CURRENT_PAGE} of {TOTAL_PAGE}"
            })

            for (const embed of cache) deploy.addEmbed(embed)

            deploy.show()

            client.deploys.set(message.author.id, deploy)
            return message.reply("deployed")
        }
        if (subcommand === "clear") {
            client.storage.delete(message.author.id)
            client.deploys.delete(message.author.id)
            return message.reply("forcibly removed embed storage")
        }
    }
})

client.login("super secret token")

Quick Usage

new EmbedPaginator({
  message: await message.channel.messages.fetch(msgResolvable),
  bindPageViewTo: "footer",
  pageView: "Page {CURRENT_PAGE} of {TOTAL_PAGE}"
})

Author

👤 zero734kr

🤝 Contribuiting

Issues and Pull Requests are welcome! If you had a problem please contact at issues page Code Change Requests are available to open pulls at PR page.

Support

If this library was useful please star⭐️ this repo

📝 License

Copyright © 2020 zero734kr. This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator

1.0.3

5 years ago

1.0.2

5 years ago

1.0.2-test2

5 years ago

1.0.2-test

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago