discordjs-prompter
v2.0.4
Published
Prompt for a user response using reactions or a message.
Downloads
64
Maintainers
Readme
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?`);
});
}
});
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!');
});
}
});
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...
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...