我目前正在尝试制作一个反应角色机器人。我已经编写了以下代码,但需要进一步的帮助以使其符合我的要求。
Code:
const { Client, MessageEmbed } = require("discord.js");
const Discord = require("discord.js");
const client = new Client();
const TOKEN = "";
client.login(TOKEN);
client.on("ready", () => {
console.log("LOGGED IN!");
});
client.on("message", (message) => {
if (message.author.bot) {
if (message.embeds) {
const embedMsg = message.embeds.find((msg) => msg.title === "Server Roles");
if (embedMsg) {
message
.react("763867011495231538")
.then((reaction) => reaction.message.react("763867011469410334"))
.then((reaction) => reaction.message.react("763867012950523915"))
.then((reaction) => reaction.message.react("763937127733919754")) //continue doing .then for more reactions
.then((msg) => console.log("Reacted to messages"))
.catch((err) => console.error);
}
}
return;
}
if (message.content.toLowerCase() === "?roles")
if (message.author.id === "350423254940516352") {
//user id
{
const rolesembed = new Discord.MessageEmbed()
.setTitle("Server Roles")
.setColor("MAGENTA")
.setDescription("<:roblox:763867011495231538> - Roblox\n" + "<:minecraft:763867011469410334> - Minecraft\n" + "<:amongus:763867012950523915> - Among Us\n" + "<:r6s:763937127733919754> - Siege");
message.channel.send(rolesembed);
}
}
client.on("messageReactionAdd", (reaction, user) => {
if (user.bot) return;
var roleName = reaction.emoji.name;
var role = reaction.message.guild.roles.cache.find((role) => role.name.toLowerCase() === roleName.toLowerCase());
var member = reaction.message.guild.members.cache.find((member) => member.id === user.id);
if (member.roles.cache.has(role.id)) {
member.roles
.remove(role.id)
.then((member) => {
console.log("Removed " + member.user.username + " from the " + role.name + " role.");
})
.catch((err) => console.error);
message.author.send("**" + "You have been removed from the role " + role.name + "**");
} else {
member.roles
.add(role.id)
.then((member) => {
console.log("Added " + member.user.username + " to the " + role.name + " role.");
})
.catch((err) => console.error);
message.author.send("**" + "You have been given the role " + role.name + "**");
}
});
});
感谢您的帮助。