Discord.js TypeError:无法读取属性';缓存&x27;未定义在Object.execute的值-需要修复

Discord.js TypeError:无法读取属性';缓存&x27;未定义在Object.execute的值-需要修复,discord.js,Discord.js,我试图使系统静音,但控制台向我发送了以下错误类型错误: 无法读取对象处未定义的属性“缓存”。请执行 然后我的机器人崩溃了。我试图删除一些代码,但机器人还是因为同样的原因继续崩溃。我试图删除“缓存”,但错误变为 TypeError:无法读取Object.execute上未定义的属性“has” 问题是变量mencionado引用的是a,而不是a Users没有.roles属性(因此为什么User.roles.cache会导致TypeError:无法读取属性“cache”… 要解决此问题,您需要使用而

我试图使系统静音,但控制台向我发送了以下错误类型错误:

无法读取对象处未定义的属性“缓存”。请执行

然后我的机器人崩溃了。我试图删除一些代码,但机器人还是因为同样的原因继续崩溃。我试图删除“缓存”,但错误变为

TypeError:无法读取Object.execute上未定义的属性“has”


问题是变量
mencionado
引用的是a,而不是a

User
s没有
.roles
属性(因此为什么
User.roles.cache
会导致
TypeError:无法读取属性“cache”…

要解决此问题,您需要使用而不是:

。。。
让mencionado=message.notices.members.first();
...
if(mencionado.roles.cache.has(rol))返回message.channel.send(“Ese usuario ya estaba muteado!”);
...

另一件需要注意的事情是,如果此命令在中运行,它也会使您的bot崩溃。

问题是变量
mencionado
引用的是a,而不是a

用户
不是成员,因此不能具有
角色
属性

要解决此问题,您需要使用而不是:

let-mencionado=message.notices.members.first();
另一件需要注意的事情是,如果此命令在中运行,它将抛出一个错误,因为dm通道没有成员,因此没有角色

const Discord = require("discord.js");
const client = new Discord.Client();
const { Client, MessageEmbed } = require("discord.js");
const ms = require('ms')
const db = require("megadb")
const muterol = new db.crearDB("muterol")

module.exports = {
    name: "mute",
    alias: [ ],
  
  async execute (client, message, args){

    var perms = message.member.hasPermission("KICK_MEMBERS")
    if(!perms) return message.channel.send("No tienes permisos suficientes para usar ese comando!")

    let time = args[1]
    if(!time) return message.channel.send("Debes decir un tiempo!")
    let timer = ms(time)

    let mencionado = message.mentions.users.first()
    if(!mencionado) return message.channel.send("Debes mencionar a alguien!")

    var razon = args[2]
    if(!razon) {
        razon = 'No especificado'
    }

    if(muterol.tiene(message.guild.id)) return message.channel.send("Este servidor no tiene ningún rol para mutear")

    let rol = await muterol.obtener(message.guild.id)

    if (mencionado.roles.cache.has(rol)) return message.channel.send("Ese usuario ya estaba muteado!")

    mencionado.roles.add(rol)

    await setTimeout(async function() {

        await mencionado.roles.remove(rol)

        await message.channel.send(`Se acabo el tiempo de mute de ${mencionado}`).catch(error => {message.channel.send(`Hubo un error inesperado! **${error}**`)
        })

    }, timer)
 
 }

}