Search code examples
node.jsdiscord.jsunhandled-promise-rejection

NodeJS/DiscordJS UnhandledPromiseRejectionWarning Error


First of all, I'm pretty new to programming. Apologies if this post sounds naive.

I'm making a Discord bot using JS, and using a command and event handler instead of everything in main.js. The error occurs when I issue the command !reactionrole.

Here is the error:

(node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

here is my code in main.js:

const Discord = require('discord.js');

const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});

const fs = require('fs');

client.commands = new Discord.Collection();
client.events = new Discord.Collection();


['command_handler', 'event_handler'].forEach(handler =>{
    require(`./handlers/${handler}`)(client, Discord);
})


client.login(process.env.token);

Here is my code in ready.js

module.exports = () => {
    console.log('The bot is online.')
}

Here is my code in reactionrole.js (a command) just in case it's needed.

module.exports = {
    name: 'reactionrole',
    description: "Sets up reaction roles",
    async execute(message, args, Discord, client) {
        const channel = '796928981047705602';
        const uploadNotifs = message.guild.roles.cache.find(role => role.name === "Upload Notifs");
        const liveNotifs = message.guild.role.cache.find(role => role.name === "Live Notifs");
        const giveNotifs = message.guild.role.cache.find(role => role.name === "Giveaways");

        const uploadNotifsEmoji = ':bell:';
        const liveNotifsEmoji = ':red_circle:';
        const giveNotifsEmoji = ':partying_face:';

        let embed = new Discord.MessageEmbed()
            .setColor('#e42643')
            .setTitle('Choose what to be notified for!')
            .setDescription('Select the types of notifications you want to recieve.\n\n'
                + `${uploadNotifsEmoji} for Upload Notifications`
                + `${liveNotifsEmoji} for Livestream Notifications`
                + `${giveNotifsEmoji} for Giveaway Notifications`);

        let messageEmbed = await message.channel.send(embed);
        messageEmbed.react(uploadNotifsEmoji);
        messageEmbed.react(liveNotifsEmoji);
        messageEmbed.react(giveNotifsEmoji);
    }
}

Thanks in advance


Solution

  • Fixed. I didn't have my params set in the correct order. Before, I had async execute(message, args, Discord, client), I changed it to execute(client, message, args, Discord). worked fine after that.