簡體   English   中英

在node.js上接收未定義的值

[英]Receiving undefined value on node.js

我需要理解為什么我收到突擊隊的未定義。 我之前定義了它,命令是正確的。

我正試圖從目錄中獲取命令。

這是一個機器人

問候。

client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

console.log(`Command read:  ${commandFiles}`);

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}

client.on('message', msg => {
    let args = msg.content.slice(prefix.length).split(/ +/); //Slices off the prefix entirely and then splits it into an array by spaces. / +/ to avoid issues with spaces
    const command = args.shift().toLowerCase(); //Variable by calling args.shift(), which will take the first element in array and return it while also removing it from the original array(so that you dont have the command name string inside the args array).

    console.log(command);

    const commando = client.commands.get(command);

   console.log(commando);
})

假設您的集合像Map對象一樣工作,則執行以下操作:

client.commands.set(command.name, command);

但是,你這樣的.get()是這樣的:

const commando = client.commands.get(command);

我認為在這兩個示例中,可能command您正在執行.get() ,這與您執行.set() command.name

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM