【发布时间】:2020-12-27 15:46:14
【问题描述】:
我正在创建一个命令,该命令将删除用户的所有角色并给他一个指定的角色。但是,我遇到了一个问题,它没有删除角色,给了我[INVALID_TYPE]: Supplied roles is not an Array or Collection of Roles or Snowflakes. 错误。我的代码如下所示:
const { DiscordAPIError } = require("discord.js");
const Discord = require("discord.js");
const fs = require("fs");
const ms = require("ms");
let antagonistRoleList = JSON.parse(
fs.readFileSync("./roleIDs/antagonistRole.json", "utf-8")
);
const commands = require("./commands");
module.exports = {
name: "antagonise",
description: "The bot will antagonise the mentioned user",
execute(message, args) {
let antagonistRoleList = JSON.parse(
fs.readFileSync("./roleIDs/antagonistRole.json", "utf-8")
);
let guildID = message.guild.id;
let antagonistRole = antagonistRoleList[guildID].antagonistRoleList;
var member = message.mentions.members.first(); // || message.guild.members.cache.get(args[0]);
var role = message.guild.roles.cache.get(
`${antagonistRoleList[guildID].antagonistRoleList}`
);
if (!member) {
var member = message.guild.members.cache.get(args[0]);
var antagReason = args.join(" ").slice(18);
} else {
var antagReason = args.join(" ").slice(22);
}
if (!member) {
return message.reply(
"please specify the user that should be antagonised"
);
}
if (!role) {
return message.reply(
"there is not a role set as the antagonist role, set it by doing &setantagonistrole (that requires manage server permissions)"
);
}
if (!antagReason) {
antagReason = "no reason given";
}
if (member.id === message.author.id) {
return message.reply("can not allow self-harm");
}
if (
message.member.roles.highest.comparePositionTo(member.roles.highest) <= 0
) {
return message.reply(
"you can not antagonise a user with the same (or higher) permissions as you"
);
}
if (!message.member.permissions.has("MANAGE_ROLES")) {
return message.reply(
`you don't have manage roles permissions that are required to execute this command.`
);
}
console.log(`${role}`);
console.log(`${antagonistRole}`);
if (member.roles.cache.has(`${antagonistRole}`)) {
return message.reply("this user is already antagonised!");
}
member.roles.remove(member.roles).catch((error) => {
console.log(error);
});
member.roles
.add(role)
.then((memberAdded) => {
message.reply(
`you have succesfully antagonised <@${member.id}> with the reason **${antagReason}**`
);
})
.catch((error) => {
console.log(error);
});
const embed = new Discord.MessageEmbed()
.setColor("#FF0000")
.setTitle(`You were antagonised in ${message.guild.name}`)
//.setAuthor(`${userinfoget.user.tag}`, userinfoget.user.displayAvatarURL())
.addFields({ name: `Antagonised by`, value: `${message.author.tag}` })
.addFields({ name: `Reason`, value: `${antagReason}` })
.setTimestamp();
member.user.send(embed).catch((error) => {
message.channel.send(
`Failed to DM <@${member.id}> the info about this action`
);
console.log(error);
});
console.log(`${antagonistRoleList[guildID].antagonistRoleList}`);
console.log(`${message.guild.name}`);
console.log(`${message.author.tag}`);
console.log(`${antagReason}`);
},
};
我做错了什么?我很确定这是 member.roles.remove(member.roles) 行中的错误,但我应该将其更改为什么?
【问题讨论】:
标签: javascript node.js discord discord.js