1.0.5 • Published 3 years ago

discord.js-form v1.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

discord.js-form

An utility to create simple forms with reactions in discord. Supports both JavaScript and TypeScript. This could be used for:

  • simple yes / no questions
  • polls
  • music players
  • scrolling lists

Usage Example

Scrolling lists

JavaScript

const discordForm = require('discord.js-form');

const scrollingList = {
    pages: [ /* page contents here */ ],
    pageIndex: 0
};

discordForm.createFormMessage(
    msg.channel,
    { content: scrollingList.pages[0] },
    [ '🔼', '🔽' ],
    {
        '🔽': async (user, form) => {
            if (scrollingList.pageIndex + 1 < scrollingList.pages.length)
                await form.message.edit(scrollingList.pages[++scrollingList.pageIndex]);

            // removes all reactions not from the user
            await form.reset();
        },
        '🔼': async (user, form) => {
            if (scrollingList.pageIndex > 0)
                await form.message.edit(scrollingList.pages[--scrollingList.pageIndex]);

            // removes all reactions not from the user
            await form.reset();
        }
    }
);

TypeScript

import { createFormMessage, IForm } from 'discord.js-form';
import { User } from 'discord.js';

const scrollingList = {
    pages: [ /* page contents here */ ],
    pageIndex: 0
};

createFormMessage(
    msg.channel,
    { content: scrollingList.pages[0] },
    [ '🔼', '🔽' ],
    {
        '🔽': async (user: User, form: IForm) => {
            if (scrollingList.pageIndex + 1 < scrollingList.pages.length)
                await form.message.edit(scrollingList.pages[++scrollingList.pageIndex]);

            // removes all reactions not from the user
            await form.reset();
        },
        '🔼': async (user: User, form: IForm) => {
            if (scrollingList.pageIndex > 0)
                await form.message.edit(scrollingList.pages[--scrollingList.pageIndex]);

            // removes all reactions not from the user
            await form.reset();
        }
    }
);

Preview

Preview GIF

License

This project is under the MIT license.

1.0.5

3 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago