嗨,我正在尝试为我的机器人制作一个色彩系统,但是该命令会创建重复的角色。这是我代码背后的基础知识。我希望它检查该角色是否已经存在,然后不再进行。我该怎么办
.gz
答案 0 :(得分:1)
if (message.guild.roles.cache.find(role => role.name == "#Red")) return false; // The role already exists.
message.guild.roles.create({ // Creating the role since it doesn't exist.
data: {
name: "#Red",
color: "#ff0000",
permissions: 0
}
}).then(role => {
message.channel.send(`Role \`${role.name}\` created!`);
});