繁体   English   中英

如何使用 fs 从 json 文件中获取 ID

[英]How can I get an ID from json file using fs

const rptch = require('./reportch.json')

let reportchannel = message.guild.channels.find('id', `${rptch}`);

我使用fs.writeFile将通道 ID 写入json文件,但我无法通过json文件 ID 获取该通道

我认为在 JSON 文件中可能是:

{
  "id": "ID"
}

在您的主文件中:

const { id } = require('./reportch.json');
let reportChannel = message.guild.channels.cache.find(channel => channel.id === id);

那么,这意味着什么?

  1. 您写下的第一行可能是错误的。 因为 JSON 文件没有id变量。

  2. 自新的 Discord.js v12 更新以来,来自message.guild.channels.find()reportChannel变量值已更改为message.guild.channels.cache.find()

它完全适合我!

注意:我正常使用。 不需要fs模块

使用 fs

data = fs.readfilesync(path)
info = JSON.parse(data)```
info['propertyname'] will give you the id.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM