每次我 运行 这段代码时我都会收到这个错误
i keep getting this error everytime i run this block of code
这是我的代码。
client.on('message', e =>{
if(e.member.role.cache.has('960191891473829929')){
if(!e.content.startsWith(p) || e.author.bot) return;
console.log('successfully unmuted')
var ar = e.content.slice(p.length).split(/ +/)
var cmd = ar.shift().toLowerCase();
if(cmd === 'us'){
var target = e.mentions.users.first();
if(target){
let mainRole = e.guild.roles.cache.find(role => role.name === 'retard')
let muteRole = e.guild.roles.cache.find(role => role.name === 'commoner')
let memberTarget = e.guild.members.cache.get(target.id);
memberTarget.roles.remove(mainRole.id)
memberTarget.roles.add(muteRole.id)
var smbed = new discord.MessageEmbed()
.setColor('GREEN')
.setTitle('success!')
.setDescription(`<@${memberTarget.user.id}> has been successfully unmuted!`)
e.channel.send({embeds: [smbed]})
} else{
var fembed = new discord.MessageEmbed()
.setColor('RED')
.setTitle('invalid user!')
.setDescription('unmute failed because there was not a valid member mentioned :(')
e.channel.send({ embeds: [fembed] })
}
}
} else {
e.channel.send({embeds: [rolefb]})
}
});
这是我遇到的错误。
TypeError: Cannot read properties of undefined (reading 'cache')
请帮助,不知道如何解决。我尝试了一切,如果只有一个人帮助,那将意义重大
它应该使具有 id 角色的人静音
这里只是一个小错别字:
if(e.member.role.cache.has('960191891473829929')){
在role
之后加一个s
:
if(e.member.roles.cache.has('960191891473829929')){
这是我的代码。
client.on('message', e =>{
if(e.member.role.cache.has('960191891473829929')){
if(!e.content.startsWith(p) || e.author.bot) return;
console.log('successfully unmuted')
var ar = e.content.slice(p.length).split(/ +/)
var cmd = ar.shift().toLowerCase();
if(cmd === 'us'){
var target = e.mentions.users.first();
if(target){
let mainRole = e.guild.roles.cache.find(role => role.name === 'retard')
let muteRole = e.guild.roles.cache.find(role => role.name === 'commoner')
let memberTarget = e.guild.members.cache.get(target.id);
memberTarget.roles.remove(mainRole.id)
memberTarget.roles.add(muteRole.id)
var smbed = new discord.MessageEmbed()
.setColor('GREEN')
.setTitle('success!')
.setDescription(`<@${memberTarget.user.id}> has been successfully unmuted!`)
e.channel.send({embeds: [smbed]})
} else{
var fembed = new discord.MessageEmbed()
.setColor('RED')
.setTitle('invalid user!')
.setDescription('unmute failed because there was not a valid member mentioned :(')
e.channel.send({ embeds: [fembed] })
}
}
} else {
e.channel.send({embeds: [rolefb]})
}
});
这是我遇到的错误。
TypeError: Cannot read properties of undefined (reading 'cache')
请帮助,不知道如何解决。我尝试了一切,如果只有一个人帮助,那将意义重大
它应该使具有 id 角色的人静音
这里只是一个小错别字:
if(e.member.role.cache.has('960191891473829929')){
在role
之后加一个s
:
if(e.member.roles.cache.has('960191891473829929')){