discordjs-prompt 👋
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 => {
if (msg.content.startsWith('!foo')) {
prompter
.message(msg.channel, {
question: 'Do you like bacon?',
userId: msg.author.id,
max: 1,
timeout: 10000,
})
.then(responses => {
if (!responses.size) {
return msg.channel.send(`No time for questions? I see.`);
}
const response = responses.first();
msg.channel.send(`**${response}** Is that so?`);
});
}
});
Reaction Prompt:
const prompter = require('discordjs-prompter');
client.on('message', msg => {
if (msg.content.startsWith('!bar')) {
prompter
.reaction(msg.channel, {
question: 'Are you sure?',
userId: msg.author.id,
})
.then(response => {
if (!response) return msg.reply('you took too long!');
if (response === 'yes') return msg.channel.send('You chose yes!');
if (response === 'no') return msg.channel.send('You chose no!');
});
}
});
Vote prompt:
Prompter.vote(message.channel, {
question: 'Cast your vote!',
choices: ['🔥', '💙'],
timeout: 3000,
}).then((response) => {
const winner = response.emojis[0];
message.channel.send(winner.emoji + ' won!!');
});
Choice prompt:
const response = await Prompter.choice(message.channel, {
question: 'Pick an emoji!',
choices: ['✨', '❌'],
userId: message.author.id
});
console.log(response);
Documentation
Go to documentation