discordjs-prompter
TypeScript icon, indicating that this package has built-in type declarations

2.0.4 • Public • Published

discordjs-prompt 👋

Version@Master Documentation License: MIT

Prompt for a user response using reactions or a message.

Features

  • Message prompt -> Get text
  • Reaction prompt -> Accept or cancel
  • Vote prompt (new) -> Collect votes
  • Choice prompt (new) -> An emoji reaction

Examples

Message Prompt:

const prompter = require('discordjs-prompter');
 
client.on('message', msg => {
  // Listen for a message starting with !foo
 
  if (msg.content.startsWith('!foo')) {
    // Prompts the user if wether they like bacon or not
 
    prompter
      .message(msg.channel, {
        question: 'Do you like bacon?',
        userId: msg.author.id,
        max: 1,
        timeout: 10000,
      })
      .then(responses => {
        // If no responses, the time ran out
        if (!responses.size) {
          return msg.channel.send(`No time for questions? I see.`);
        }
        // Gets the first message in the collection
        const response = responses.first();
 
        // Respond
        msg.channel.send(`**${response}** Is that so?`);
      });
  }
});

alt text


Reaction Prompt:

const prompter = require('discordjs-prompter');
 
client.on('message', msg => {
  // Listen for a message starting with !bar
  if (msg.content.startsWith('!bar')) {
    // Asks if user is sure
    prompter
      .reaction(msg.channel, {
        question: 'Are you sure?',
        userId: msg.author.id,
      })
      .then(response => {
        // Response is false if time runs out
        if (!response) return msg.reply('you took too long!');
        // Returns 'yes' if user confirms and 'no' if ser cancels.
        if (response === 'yes') return msg.channel.send('You chose yes!');
        if (response === 'no') return msg.channel.send('You chose no!');
      });
  }
});

alt text


Vote prompt:

  // ...other discordjs logic
  Prompter.vote(message.channel, {
    question: 'Cast your vote!',
    choices: ['🔥', '💙'],
    timeout: 3000,
  }).then((response) => {
    const winner = response.emojis[0];
    message.channel.send(winner.emoji + ' won!!');
  });
  // other discordjs logic...

alt text


Choice prompt:

  // ...other discordjs logic
  const response = await Prompter.choice(message.channel, {
    question: 'Pick an emoji!',
    choices: ['', ''],
    userId: message.author.id
  });
  console.log(response); // -> ✨ or ❌ or null if user doesn't respond
  // other discordjs logic...

Documentation

Go to documentation

Package Sidebar

Install

npm i discordjs-prompter

Weekly Downloads

65

Version

2.0.4

License

MIT

Unpacked Size

25.4 kB

Total Files

11

Last publish

Collaborators

  • joaquimnet