Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.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:无法读取属性';设置';未定义Discord.js的_Javascript_Node.js_Set_Discord.js_Pls - Fatal编程技术网

Javascript TypeError:无法读取属性';设置';未定义Discord.js的

Javascript TypeError:无法读取属性';设置';未定义Discord.js的,javascript,node.js,set,discord.js,pls,Javascript,Node.js,Set,Discord.js,Pls,我正在使用discord.js,下面是我的代码: const client = new Discord.Client(); const fs = require('fs'); const { get } = require('http'); client.commands = new Discord.Collection(); const commandFiles = fs.readdirSync('./Commands/').filter(file => file.endsWith

我正在使用discord.js,下面是我的代码:

const client = new Discord.Client();

const fs = require('fs');
const { get } = require('http');

client.commands = new Discord.Collection();

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

const set = new Set();

for(const file of commandFiles){
  const command = require(`./Commands/${file}`);

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

const config = require('./config.json');

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', msg => {
  if (!msg.content.startsWith(prefix) || msg.author.bot) return;

  const args = msg.content.slice(prefix.length).trim().split('/ +/ ');
  const command = args.shift().toLowerCase();
  // ...

  if (!client.commands.has(commandName)) return;

  const Command = client.commands.get(commandName);

  try {
     Command.execute(message, args);
  } catch (error) {
  // ...
  }

  try {
    client.commands.get(command).execute(message, args);
  } catch (error) {
    console.error(error);
    message.reply('there was an error trying to execute that command!');
  }

});
client.on('message', msg => {
  if (msg.content === 'ping') {
    client.commands.get('ping').execute(message, args);
  }else if (msg.content === 'pong') {
    msg.reply('Ping!')
  }else if (msg.content === `${prefix}beep`) {
    msg.channel.send('Boop!');
  }else if (msg.content === `${prefix}boop`) {
    msg.channel.send('Beep!');
  }else if (msg.content === `${prefix}server`) {
    msg.channel.send(`This server's name is: ${msg.guild.name}\nTotal members: 
    ${msg.guild.memberCount}`);
  }else if (msg.content === `${prefix}user-info`) {
    msg.channel.send(`Your username: ${msg.author.username}\nYour ID:    ${msg.author.id}`);
  }

});

const { prefix, token } = require('./config.json');
//...

client.login(config.token);
她是我的错误,在你问之前:是的,我有一个config.json

错误:

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

TypeError: Cannot read property 'set' of undefined
at Object.<anonymous> (C:\Users\Scare\Desktop\spagehtt\index.js:17:18)
?[90m    at Module._compile (internal/modules/cjs/loader.js:1133:30)?[39m
?[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)?[39m
?[90m    at Module.load (internal/modules/cjs/loader.js:977:32)?[39m
?[90m    at Function.Module._load (internal/modules/cjs/loader.js:877:14)?[39m
?[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)?[39m
?[90m    at internal/main/run_main_module.js:18:47?[39m
PS C:\Users\Scare\Desktop\spagehtt>
client.command.set(command.name,command);
TypeError:无法读取未定义的属性“set”
反对。(C:\Users\Scare\Desktop\spagehtt\index.js:17:18)
?模块处为[90m.\u编译(内部/modules/cjs/loader.js:1133:30)?[39m
?在Object.Module._extensions..js处为[90米(内部/modules/cjs/loader.js:1153:10)?[39米
?模块加载时为90米(内部/模块/cjs/loader.js:977:32)?[39米
?功能模块加载时为[90米(内部/modules/cjs/loader.js:877:14)?[39米
?在Function.executeUserEntryPoint[作为runMain](内部/模块/run_main.js:74:12)处为[90米]?[39米
?内部/主/运行主模块处为90米。js:18:47?[39米
PS C:\Users\Scare\Desktop\spagehtt>

这就是我的问题,它阻止我打开我的bot并运行我正在测试的命令,所以我真的需要帮助。

正如你所看到的
客户端。command
没有
.set
,但是
客户端。commands

解决方案:


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

确定完成,但如果(!client.commands.has(commandName))出现另一个问题return;^ReferenceError:commandName未定义如果已定义,请将其标记为解决方案。
commandName
未在您的代码中定义。您是否在某个地方复制了此代码,因为我认为您不清楚它。我已修复此问题,但我知道如何定义ToLowerCase。您是否可以将其标记为解决方案请发表评论,并开始另一个问题的新线程?对不起,我不知道怎么做