Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:无法读取属性';varName';未定义的_Javascript_Discord_Discord.js - Fatal编程技术网

Javascript TypeError:无法读取属性';varName';未定义的

Javascript TypeError:无法读取属性';varName';未定义的,javascript,discord,discord.js,Javascript,Discord,Discord.js,这是我的密码。我不断收到TypeError:无法读取未定义和类似错误的属性' const data = cache.actions[cache.index]; let varName = this.evalMessage(data.varName, cache); let storage = parseInt(data.storage); let info = parseInt(data.info); let time = parseInt(data.time); const { msg } =

这是我的密码。我不断收到
TypeError:无法读取未定义和类似错误的属性'

const data = cache.actions[cache.index];
let varName = this.evalMessage(data.varName, cache);
let storage = parseInt(data.storage);
let info = parseInt(data.info);
let time = parseInt(data.time);
const { msg } = cache
const { guild } = cache

if (guild.varName === undefined) {
guild.varName = new Set();
}
    if (message.guild.varName.has(msg.author.id)) {
            channel.send("info");
            console.log("Restriction active!");
} else {

        message.guild.varName.add(msg.author.id);
        setTimeout(() => {

        message.guild.varName.delete(msg.author.id);
        }, time);
        
    }`

看起来这里有两个主要问题。首先,这段代码中没有消息收集器。消息收集器类似于

client.on('message', function() {
    //some code here
}

这将等待bot接收消息,然后执行函数中的任何操作。我看到的第二个问题是,您有一个变量
varName
,您正试图使用该变量访问
guild
的属性。在代码中,您使用了点表示法,但在尝试使用变量访问属性时,点表示法不起作用。您的代码将查找名为
“varName”
(请注意,它是一个字符串)的guild属性,而您应该查找名为
varName
的属性。要做到这一点,您可以使用
guild[varName]

消息从何而来?@TheRealPikachu您不想使用guild.varName,但要在任何地方使用guild[varName]来使用动态对象属性。您的错误在哪一行?