#UnhandledPromiseRejection This error originated either by throwing inside of an async function
1 messages Β· Page 1 of 1 (latest)
const { SlashCommandBuilder } = require('@discordjs/builders')
module.exports = {
data: new SlashCommandBuilder()
.setName('vote')
.setDescription('(For Chip Only!) Make a poll!')
.addStringOption(option =>
option.setName('question')
.setDescription('The question to be asked')
.setRequired(true)),
async execute(interaction, client, MessageEmbed, minutes) {
// Grab the question from the interaction options
const question = interaction.options.getString('question')
// Define poll embed
let poll = new MessageEmbed()
.setTitle(`Poll: ${question}`)
.setDescription('React with the appropriate emoji to vote!')
.setFooter({ text: 'Wee6, a bot by ChunkleChip', iconURL: `https://cdn.discordapp.com/avatars/${client.user.id}/${client.user.avatar}.png?size=4096` })
// Define the reply to the interaction, which is the poll question itself
poll = await interaction.reply({ embeds: [poll], fetchReply: true })
// Add reactions and consequently send reply at the same time
poll.react('π').then(() => poll.react('π')).then(() => poll.react('π€·ββοΈ'))
// Define a filter for the reactions once they've been collected
const filter = (reaction, user) => {
return (['π', 'π', 'π€·ββοΈ'].includes(reaction.emoji.name) && user.id === message.author.id)
}
// Wait 10 seconds for reactions to be collected, then map the reactions for parsing as a edit to the original embed
poll.awaitReactions({ filter, max: 65535, time: 10000, errors: ['time'] })
.then(collected => {
const results = collected.map(reaction => reaction.count)
const totalVotes = results.reduce((a, b) => a + b, 0)
const resultsString = results.map(result => `${result} ${result.emoji.name}`).join(', ')
interaction.editReply({ content: `Results: ${resultsString}. Total: ${totalVotes}`, ephemeral: false })
})
},
}
I will admit, I don't fully understand promises, but I am trying my best.
so what is the full error of the code ?
Oh, I guess I should ask a question. What am I doing wrong here? This is the full error.
3/31/2022, 11:38:43 AM - Bot is online, Logged in as 'Wee6-V3'
-- BOT MESSAGE: --
node:internal/process/promises:279
triggerUncaughtException(err, true /* fromPromise */);
^
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<r>".] {
code: 'ERR_UNHANDLED_REJECTION'
}
Node.js v17.8.0
is this cause after user react or before it
the error is not really clear which cause it tho 
That's my point exactly. It throws this error after the embed gets sent then has reactions put on it.
After the 10 second timeout
you can try to try catch it to see errors
try {
// block of code
} catch (error) {
console.error(error)
}
Alright, lemme take a crack at it.

const { SlashCommandBuilder } = require('@discordjs/builders')
module.exports = {
data: new SlashCommandBuilder()
.setName('vote')
.setDescription('(For Chip Only!) Make a poll!')
.addStringOption(option =>
option.setName('question')
.setDescription('The question to be asked')
.setRequired(true)),
async execute(interaction, client, MessageEmbed, minutes) {
const question = interaction.options.getString('question')
let poll = new MessageEmbed()
.setTitle(`Poll: ${question}`)
.setDescription('React with the appropriate emoji to vote!')
.setFooter({ text: 'Wee6, a bot by ChunkleChip', iconURL: `https://cdn.discordapp.com/avatars/${client.user.id}/${client.user.avatar}.png?size=4096` })
interaction.reply({ embeds: [poll], fetchReply: true }).then(async (message) => {
await message.react('π')
await message.react('π')
message.awaitReactions({ max: 10, time: 10000, errors: ['time'] })
.then(collected => {console.log(collected.size)})
.catch(collected => {
const upDoot = collected.get('π').count - 1
const downDoot = collected.get('π').count - 1
const embed = new MessageEmbed()
.setTitle(`Poll Results: ${question}`)
.setDescription(`${upDoot} people voted for π\n\n${downDoot} people voted for π`)
.setFooter({ text: 'Wee6, a bot by ChunkleChip', iconURL: `https://cdn.discordapp.com/avatars/${client.user.id}/${client.user.avatar}.png?size=4096` })
message.edit({ embeds: [embed] })
})
})
},
}
Update for how I fixed it π