[英]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);
您写下的第一行可能是错误的。 因为 JSON 文件没有id
变量。
自新的 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.