首先,我对编程很陌生。抱歉,如果这篇文章听起来很幼稚。
我正在使用 JS 制作一个 Discord 机器人,并使用命令和事件处理程序而不是 main.js 中的所有内容。当我发出命令时发生错误!reactionrole
。
这是错误:
(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)
这是我在 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);
这是我在 ready.js 中的代码
module.exports = () => {
console.log('The bot is online.')
}
这是我在reactionrole.js(命令)中的代码,以防万一。
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);
}
}
提前致谢