So lets begin fixing the code!
module.exports = {
name: 'reactionrole',
description: 'A Reaction Message!',
async execute(message, args, Discord, client){
const channel = '797456859165491250';
const reactRole = message.guild.roles.cache.find(role => role.name === "NameOfRole");
This codes asks for a channel that the message will be posted in and the name of the role you want to give !
Then you need to ask for the emoji.If you want a custom emoji the easiest way is to send ,in a test channel, the emoji that you want to set and if you right click on the emoji, at the bottom , it's says "OPEN LINK" . If you open that link in your browser it will show something like this : "https://cdn.discordapp.com/emojis/791979565056000000.png?v=1" You need to copy the numbers in the end and paste is in the section "emojiID"
Example:
const reactionEmoji = client.emojis.cache.get("791979565056000000");
While you have the id of the custom emoji, you need to apply it in the code, so your next step is :
const reactionEmoji = client.emojis.cache.get("emojiID");
UPDATE:
Under the above code you need to set a message for the bot to react!You need to do this :
let embed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setTitle('Some Title')
.setDescription('**some description**
'
+ `> **${reactionEmoji} for Role**
`)
let messageEmbed = await message.channel.send(embed);
message.delete();
messageEmbed.react(reactionEmoji);
client.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 === channel) {
if (reaction.emoji.name === reactionEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(reactRole)
}
} else {
return;
}
});
client.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 === channel) {
if (reaction.emoji.name === reactionEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(reactRole)
}
}
} else {
return;
}
});
},
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…