npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

advanced-discord.js-prompts

v2.1.2

Published

An advanced list of prompts available to developers to create Discord bots with Discord.js

Downloads

15

Readme

Advanced Discord.js Prompts

This JavaScript module brings over 20 different types of prompts to interact with users via Discord using Discord.js and/or Discord.js-commando.

Features

Highly Customizable

All prompts can be easily customizable. In the future we hope to introduce the use of embeds with even more customization!

Time limit

Prompts can be given a time limit. Users will have to resolve the prompt within that time frame.

Prompt Cancellation

Most prompts can be canceled by the user. However, the developer can mark prompts as not cancelable.

Safe User-Guided Prompts

Prompts are user guided, this means only one user is allowed to respond to the prompt. This allows you to send multiple prompts to different users to the same channel with no issues.

Discord.js Oriented Prompts

We have Discord.js specific prompts like Member, Channel, Emoji, and Role prompts which will return the Discord.js Objects for easier development.

Advanced List Prompts

The ListPrompt class has customizable prompts that allow the user to select one or many options out of a list of options. They can be used with anything (Channels, Roles, Text, Numbers)!

Fully Tested and 100% Test Coverage

This package is 100% Test Covered and it is used by other bots we produce!

Usage

Check our Documentation

You can take a look at our documentation with tutorials here!

Basic Tutorial

  1. Install the npm package (add '--production' to not install our unit testing packages)
npm install advanced-discord.js-prompts --production
  1. Import the prompt type that you need.
const { MemberPrompt } = require('advanced-discord.js-prompts');
  1. Use the static functions.
let guildMember = await MemberPrompt.single({
    prompt: 'Please tag your friend',
    channel: message.channel,
    userId: message.author.id,
    time: Infinity, // Infinity by default (no time limit)
    cancelable: false // true by default
});

If you want to have a time limit or for the prompt to be cancelable you need to expect either of the two errors.

try {
    var guildMember = await MemberPrompt.single({
        prompt: 'Please tag your friend',
        channel: message.channel,
        userId: message.author.id,
        time: Infinity, // Infinity by default (no time limit)
        cancelable: false // true by default
    });
} catch (error) {
    // add the error to the require clause const = { TimeOutError, MemberPrompt } ...
    // you can also check the error name (error.name === 'TimeOutError')
    if (error == TimeOutError) {
        // the user timed out
    } 
    // add the error to the require clause const = { CancelError, MemberPrompt } ...
    // you can also check the error name (error.name === 'CancelError')
    else if (error == CancelError) {
        // the user canceled the prompt
    }
}

Structure

All prompts follow the same structure, naming convention and information needed. Each prompt type is divided in classes with similar output, for example, the ChannelPrompt class has static functions that will prompt and return Channels.

Errors

Apart from the TimeOutError and CancelError that you should expect for ass seen in the usage section. The module will show errors if the prompt information is not valid. You should fix those in code, the user can not fix these errors.

Prompt Info

All prompts require prompt information. The prompt information consists of:

  • prompt -> the text to use to prompt the user
  • channel -> the text or DM channel to prompt the user on
  • userId -> the user's ID to be prompted
  • time? -> (optional) the amount of time the user has to resolve the prompt
  • cancelable? -> (optional) if the user can cancel the prompt

Available Prompts

Message Prompt

The message prompt is the base prompt for most other prompts. It will request the basic prompt information and return a Discord.js Message object.

Channel Prompt

Prompts the user for Discord text channels by responding with a mention.

Member Prompt

Prompts the user for guild members by responding with user mentions.

Number Prompt

Prompts the user for x amount of numbers. Prompt ensures the response are numbers only.

Role Prompt

Prompts the user for Guild Roles by responding with a role mention.

String Prompt

Prompts the user for a string or text.

List Prompt

Prompts the user to select one or x amount of options out of a list either via emoji reaction or by typing list indexes.

Special Prompt

Prompts the user for emojis or for a yes/no response for boolean values.

Development

Please feel free to add feature request or bug issues on our github. We are constantly developing this package for our other bots!

Future Plans

  • [x] add unit testings
  • [ ] add tutorials
  • [ ] add embed support
  • [ ] add optional console logging with winston

Authors

Juan Pablo Garcia Maggie Wang