const rptch = require('./reportch.json')
let reportchannel = message.guild.channels.find('id', `${rptch}`);
I used fs.writeFile that writes a channel ID into a json file, but I can't get that channel by the json file id
const rptch = require('./reportch.json')
let reportchannel = message.guild.channels.find('id', `${rptch}`);
I used fs.writeFile that writes a channel ID into a json file, but I can't get that channel by the json file id
I think in the JSON file might be:
{
"id": "ID"
}
In Your main file:
const { id } = require('./reportch.json');
let reportChannel = message.guild.channels.cache.get(id);
The first line you wrote down may be wrong. Because there's no id variable for the JSON file.
The reportChannel variable value from message.guild.channels.get() has been changed to message.guild.channels.cache.get() since new Discord.js v12 update.
It completly works for me!
fs module neededWith fs use something like this:
fs = require('fs')
data = fs.readfilesync(path)
info = JSON.parse(data)
info['propertyname'] //Will give you the id.