我试图创建一个反应角色命令,该命令根据成员对指定 message
的反应为成员分配角色。到目前为止一切正常,除非我重新启动机器人。重启后,这个需要响应的 message
被删除,我必须创建一个新的。
这是我目前的尝试:
const Discord = require("discord.js");
const botsettings = require("../botsettings.json");
const guildidDB = require('../models/ModSchema');
module.exports.run = async (bot, message, arg) => {
const bot = new Discord.Client({partials: ["MESSAGE", "CHANNEL", "REACTION"]});
if (!message.member.hasPermission('MANAGE_MESSAGES')) return message.channel.send('**You do not have permission to execute this command!**')
const channel = message.mentions.channels.first()
const RedRole = message.guild.roles.cache.find(role => role.name === "Red")
const BlueRole = message.guild.roles.cache.find(role => role.name === "Blue")
const YellowRole = message.guild.roles.cache.find(role => role.name === "Yellow")
const GreenRole = message.guild.roles.cache.find(role => role.name === "Green")
const RedEmoji = '?'
const BlueEmoji = '?'
const YellowEmoji = '?'
const GreenEmoji = '?'
if(!channel) return message.channel.send(`<@${message.author.id}>, **Mention a channel to send the message in!**`)
const ReactionRoles = new Discord.MessageEmbed()
.setTitle("Select a color so your name can be cooler than everyone else's!")
.addField(`${RedEmoji} - RED`, 'ooooooo red is a nice color')
.addField(`${BlueEmoji} - BLUE`, 'Blue is ok')
.addField(`${YellowEmoji} - YELLOW`, 'Yelow is uhhh mehh')
.addField(`${GreenEmoji} - GREEN`, 'Green is kinda good')
.setColor('#e42643')
.setFooter("AYO REACT WITH THE COLOR U WANT")
let messageEmbed = await channel.send(ReactionRoles);
messageEmbed.react(RedEmoji)
messageEmbed.react(BlueEmoji)
messageEmbed.react(YellowEmoji)
messageEmbed.react(GreenEmoji)
bot.on('messageReactionAdd', 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 === "828948095571198004") {
if (reaction.emoji.name === RedEmoji) {
console.log("Added role")
await reaction.message.guild.members.cache.get(user.id).roles.add(RedRole)
}
if (reaction.emoji.name === BlueEmoji) {
console.log("Added role")
await reaction.message.guild.members.cache.get(user.id).roles.add(BlueRole)
}
if (reaction.emoji.name === YellowEmoji) {
console.log("Added role")
await reaction.message.guild.members.cache.get(user.id).roles.add(YellowRole)
}
if (reaction.emoji.name === GreenEmoji) {
console.log("Added role")
await reaction.message.guild.members.cache.get(user.id).roles.add(GreenRole)
}
} else {
return;
}
});
bot.on('messageReactionRemove', 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 === "828948095571198004") {
if (reaction.emoji.name === RedEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(RedRole)
}
if (reaction.emoji.name === BlueEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(BlueRole)
}
if (reaction.emoji.name === YellowEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(YellowRole)
}
if (reaction.emoji.name === GreenEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(GreenRole)
}
} else {
return;
}
});
}
module.exports.config = {
name: "selfroles",
description: "AAAAAAAa",
usage: "q!selfroles #channel",
accessableby: "Everyone",
aliases: ['']
}
有人知道导致删除此消息的错误吗?