[英]Discord Role not getting created
我正在發出靜音命令,並且在大多數情況下它可以工作,當“靜音”角色存在時,它會毫無問題地將其提供給成員,並且一切正常,但是當角色不存在時,它會給我錯誤;
Supplied roles is not a Role, Snowflake or Array or Collection of Roles or Snowflakes.
這是代碼:
const BaseCommand = require('../../utils/structures/BaseCommand');
const Discord = require('discord.js');
module.exports = class MuteCommand extends BaseCommand {
constructor() {
super('mute', 'moderation', []);
}
async run(client, message, args) {
if(!message.member.hasPermission("MUTE_MEMBERS")) return message.channel.send("You do not have Permission to use this command.");
if(!message.guild.me.hasPermission("MUTE_MEMBERS")) return message.channel.send("I do not have Permissions to mute members.");
const Embedhelp = new Discord.MessageEmbed()
.setTitle('Mute Command')
.setColor('#6DCE75')
.setDescription('Use this command to Mute a member so that they cannot chat in text channels nor speak in voice channels')
.addFields(
{ name: '**Usage:**', value: '=mute (user) (time) (reason)'},
{ name: '**Example:**', value: '=mute @Michael stfu'},
{ name: '**Info**', value: 'You cannot mute yourself.\nYou cannot mute me.\nYou cannot mute members with a role higher than yours\nYou cannot mute members that have already been muted'}
)
.setFooter(client.user.tag, client.user.displayAvatarURL());
const mentionedMember = message.mentions.members.first() || await message.guild.members.fetch(args[0]);
let reason = args.slice(1).join(" ");
const muteEmbed = new Discord.MessageEmbed()
.setTitle('You have been Muted in '+message.guild.name)
.setDescription('Reason for Mute: '+reason)
.setColor('#6DCE75')
.setTimestamp()
.setFooter(client.user.tag, client.user.displayAvatarURL());
let role = 'Muted';
let newrole = message.guild.roles.cache.find(x => x.name === role);
if (typeof newrole === undefined) {
await message.guild.roles.create({
data: {
name: 'Muted',
color: '#414247',
permissions: {
SEND_MESSAGES: false,
ADD_REACTIONS: false,
SPEAK: false
}
},
reason: 'to mute people',
})
.catch(console.log(err)); {
message.channel.send('Could not create muted role');
};
if (!reason) reason = 'No reason provided';
if (!args[0]) return message.channel.send(Embedhelp);
if (!mentionedMember) return message.channel.send(Embedhelp);
if (!mentionedMember.bannable) return message.channel.send(Embedhelp);
if (mentionedMember.user.id == message.author.id) return message.channel.send(Embedhelp);
if (mentionedMember.user.id == client.user.id) return message.channel.send(Embedhelp);
if (mentionedMember.roles.cache.find(x => x.name === role)) return message.channel.send(Embedhelp);
if (message.member.roles.highest.position <= mentionedMember.roles.highest.position) return message.channel.send(Embedhelp);
mendtionedMember.roles.add(newrole)
.catch(err => {
console.log(err); {
return message.channel.send('I was unable to mute the user');
};
}).then(() => {
message.channel.send('Successfully Muted '+mentionedMember.user.tag);
});
} else {
if (!reason) reason = 'No reason provided';
if (!args[0]) return message.channel.send(Embedhelp);
if (!mentionedMember) return message.channel.send(Embedhelp);
if (!mentionedMember.bannable) return message.channel.send(Embedhelp);
if (mentionedMember.user.id == message.author.id) return message.channel.send(Embedhelp);
if (mentionedMember.user.id == client.user.id) return message.channel.send(Embedhelp);
if (mentionedMember.roles.cache.find(x => x.name === role)) return message.channel.send(Embedhelp);
if (message.member.roles.highest.position <= mentionedMember.roles.highest.position) return message.channel.send(Embedhelp);
await mentionedMember.roles
.add(newrole)
.catch(err => {
console.log(err); {
return message.channel.send('I was unable to mute the user');
}
}).then(() => {
message.channel.send('Successfully Muted '+mentionedMember.user.tag);
});
};
}
}
創建角色的部分是;
let newrole = message.guild.roles.cache.find(x => x.name === role);
if (typeof newrole === undefined) {
await message.guild.roles.create({
data: {
name: 'Muted',
color: '#414247',
permissions: {
SEND_MESSAGES: false,
ADD_REACTIONS: false,
SPEAK: false
}
},
reason: 'to mute people',
})
.catch(console.log(err)); {
message.channel.send('Could not create muted role');
};
它檢查靜音角色是否已經存在,如果不存在,它會創建一個靜音角色,我不確定錯誤是否源自這里,但我相信它無法創建角色,這就是它不存在的原因,它無法將其提供給上述用戶,如果有任何方法可以解決此問題,請告訴我。
我不明白您為什么要針對與我已經回答您的問題的問題相同的問題發布新帖子,並在您昨天創建的上一篇帖子中給出了明確的說明。 這是問題的答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.