javascript - 重启后 Discord.js 反应角色不起作用
问题描述
我试图创建一个反应角色命令,该命令根据成员对指定的message
. 到目前为止一切正常,除非我重新启动机器人。重新启动后message
,需要对其做出反应的 this 被删除,我必须创建一个新的。
这是我迄今为止的尝试:
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: ['']
}
有人识别导致删除此消息的错误吗?
解决方案
推荐阅读
- react-native - 地铁捆绑器错误:::ffff:127.0.0.1 - - [DATE] "GET
更新:
- 我找到了一种解决方法。我在应用程序中使用的(许多)软件包之一是 react-native-device-info。如果我不在应用程序内调用它,问题就消失了(即使应用程序仍包含在构建中
- mysql - 在单个外部 SELECT 查询中使用来自 SELECT 子查询的两个聚合值
- excel - 如果excel列中的每个名称都有匹配的日期,如何获得布尔答案
- c# - (Unity) semaphore.wait for signal android 减慢了我的游戏速度
- python - 按升序对浮点数列表中的数字进行分组
- powershell - powershell - Get-Credential PScredential 对象不同于 New-Object -TypeName "System.Management.Automation.PSCredential"
- go - Go Mod 试图下载一个不存在的包
- java - 如何在@Scheduled 中运行@Async 方法
- javascript - React.js如何将字符串base64转换为普通图像
- r - R中的绝对偏差公式