【发布时间】:2021-10-01 19:06:49
【问题描述】:
我目前正在创建一个反应角色事件,人们可以在其中与消息交互并在单击某个表情符号后获得分配给自己的角色,但是由于某种原因,该事件不会触发并且没有角色分配给用户。
下面是我的reaction.js事件文件:
module.exports = async(reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === 'pinkEmoji') {
await reaction.message.guild.members.cache.get(user.id).roles.add(pink);
}
if (reaction.emoji.name === 'yellowEmoji') {
await reaction.message.guild.members.cache.get(user.id).roles.add(yellow);
}
if (reaction.emoji.name === 'purpleEmoji') {
await reaction.message.guild.members.cache.get(user.id).roles.add(purple);
}
} else {
return;
}
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === 'pinkEmoji') {
await reaction.message.guild.members.cache.get(user.id).roles.remove(pink);
}
if (reaction.emoji.name === 'yellowEmoji') {
await reaction.message.guild.members.cache.get(user.id).roles.remove(yellow);
}
if (reaction.emoji.name === 'purpleEmoji') {
await reaction.message.guild.members.cache.get(user.id).roles.remove(purple);
}
} else {
return;
}
}
我还使用命令让机器人知道它必须在输入命令后发送消息。
如果有帮助,这是我的reactionrole.js 命令文件:
module.exports = {
name: 'reactionrole',
description: 'sets up a reaction role message!',
permissions: ["MANAGE_ROLES"],
cooldown: 10,
async execute(message, args, cmd, client, Discord) {
const channel = process.env.WELCOME;
const pink = message.guild.roles.cache.find(role => role.name === "Pink");
const yellow = message.guild.roles.cache.find(role => role.name === "Yellow");
const purple = message.guild.roles.cache.find(role => role.name === "Purple");
const pinkEmoji = '????';
const yellowEmoji = '????';
const purpleEmoji = '????';
let embed = new Discord.MessageEmbed()
.setColor('#e42643')
.setTitle('Choose your own **Color Role**!')
.setDescription('Choosing a color role will give you a coloured name!\n\n'
+ `${pinkEmoji} for pink color\n`
+ `${yellowEmoji} for yellow color\n`
+ `${purpleEmoji} for purple color`);
let messageEmbed = await message.channel.send(embed);
messageEmbed.react(pinkEmoji);
messageEmbed.react(yellowEmoji);
messageEmbed.react(purpleEmoji);
}
}
下面是我正在使用的事件处理程序:
const fs = require('fs');
module.exports = (client, Discord) => {
const load_dir = (dirs) => {
const event_files = fs.readdirSync(`./events/${dirs}`).filter(file => file.endsWith('.js'));
for (const file of event_files) {
const event = require(`../events/${dirs}/${file}`);
const event_name = file.split('.')[0];
client.on(event_name, event.bind(null, Discord, client));
}
}
['client', 'guild'].forEach(e => load_dir(e));
}
我已经坚持了很长一段时间,我不知道问题出在哪里,因为它没有抛出任何错误。
【问题讨论】:
标签: javascript discord discord.js