Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.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 检索通道标识符时出现问题-Discord.JS_Javascript - Fatal编程技术网

Javascript 检索通道标识符时出现问题-Discord.JS

Javascript 检索通道标识符时出现问题-Discord.JS,javascript,Javascript,我有这样的东西…… const channel = await message.guild.createChannel("channel-name", { type: 'text', permissionOverwrites: [{ id: message.guild.id, deny: ['SEND_MESSAGES','SEND_TTS_MESSAGES'] }] }).then(channel => { channe

我有这样的东西……

  const channel = await message.guild.createChannel("channel-name", {
    type: 'text',
      permissionOverwrites: [{
      id: message.guild.id,
      deny: ['SEND_MESSAGES','SEND_TTS_MESSAGES']
    }]
  }).then(channel => {
    channel.setTopic("Topic")
  });

  const loc = "./data/test.json";
  let data = JSON.parse(fs.readFileSync(loc));
  data = {
    channel.id
  };

  fs.writeFileSync(loc, JSON.stringify(data, null, 2), (err) => {
    if(err) console.log(err)
  });
我想将通道ID“channel name”保存在json文件中,但出现了此错误

(节点:16060)未处理的PromisejectionWarning:TypeError:无法读取未定义的属性“id”

语言:discord.js、node.js


该错误意味着找不到或未定义变量previor
.id
。但是,这也可能意味着变量不包含该路径。这就是问题所在。您编写的id路径是
channel.id
,但是,id变量实际上位于
channel.permissions覆盖[0]。id


通道>许可覆盖(arr的第一个元素)>id值

更新代码的这一部分,您应该不会有问题:

  const loc = "./data/test.json";
  let data = JSON.parse(fs.readFileSync(loc));
  data = {
    channel.permissionOverwrites[0].id // Change path to id
  };

该错误意味着找不到或未定义变量previor
.id
。但是,这也可能意味着变量不包含该路径。这就是问题所在。您编写的id路径是
channel.id
,但是,id变量实际上位于
channel.permissions覆盖[0]。id


通道>许可覆盖(arr的第一个元素)>id值

更新代码的这一部分,您应该不会有问题:

  const loc = "./data/test.json";
  let data = JSON.parse(fs.readFileSync(loc));
  data = {
    channel.permissionOverwrites[0].id // Change path to id
  };

错误在哪一行?错误在哪一行?