我已经在Discord僵尸程序中使用相同的反应角色代码几个月了,但是在过去的几天里突然间,该僵尸程序不会给任何人任何角色。我不知道怎么了我的漫游器具有权限,并且没有返回任何错误消息。这是我添加和删除角色的代码。
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id === '741419143315587072') {
if (reaction.emoji.name === 'Mario1') {
await reaction.message.guild.members.cache
.get(user.id)
.roles.add('756305200414720022');
}
}
});
client.on('messageReactionRemove', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id === '741419143315587072') {
if (reaction.emoji.name === 'Mario1') {
await reaction.message.guild.members.cache
.get(user.id)
.roles.remove('756305200414720022');
}
}
});
Partials
在这里定义。
const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION"] });
这是我希望人们对这个角色做出反应的信息。
const Discord = require('discord.js');
module.exports.run = async (client, message, args) => {
if (!message.member.hasPermission('ADMINISTRATOR')) {
return message.reply(
'you lack sufficiant permissions to execute this command.'
);
}
let embed = new Discord.MessageEmbed()
.setTitle('Fighters 1-18')
.setColor('#cf200a');
let msgEmbed = await message.channel.send(embed);
msgEmbed.react('695364267494342718'); //Mario
};
module.exports.config = {
name: '1-18',
description:
'Sends a message and reacts to it with all the fighters from numbers 1-18.',
usage: '!1-18',
accessableby: 'Moderators',
aliases: [],
};
答案 0 :(得分:0)
这是一个实际示例,因此您可以修改详细信息、添加条件格式或其他内容。
//Call External Required Libraries
const Discord = require('discord.js');
//Create a Discord Client Object
const asilem = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
//Call Developer Required Libraries
const { token, prefix } = require('./package.json'); // Taking token from configJson
//Launch the client and must be executed one time
asilem.once('ready', () => {
console.log('Ready!');
});
//Get App Token from config.json file
asilem.login(token);
asilem.on('messageReactionAdd', async (reaction, user) => {
// When we receive a reaction we check if the reaction is partial or not
if (reaction.partial) {
// If the message this reaction belongs to was removed the fetching might
result in an API error, which we need to handle
try {
await reaction.fetch();
} catch (error) {
console.error('Something went wrong when fetching the message: ', error);
// Return as `reaction.message.author` may be undefined/null
return;
}
}
// Assign role with reaction
reaction.message.guild.members.cache.get(user.id).roles.add('760324295674298378');
});