I'm getting the following error: TypeError: Cannot read properties of null (reading 'id') at /index.js:144:31. My index.js code is below:
if(interaction.customId == 'generateCode') {
// defer
await interaction.deferReply({ ephemeral: true });
// already generated?
data = JSON.parse(fs.readFileSync(`./system/index.json`));
*This is row 144, user.id is the issue*
if(data.filter(t => t.id == interaction.user.id)[0]) {
embed = new MessageEmbed()
.setColor('DARK_BLUE')
.setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL() })
.setDescription("`"+data.filter(t => t.id == interaction.user.id)[0].code+"`")
await interaction.editReply({ embeds: [embed] });
return
}
The error is telling you that your user object is null. It looks like the data = JSON.parse(fs.readFileSync()) is not pulling in the file.
Based on this: JSON.parse(fs.readFileSync()) returning a buffer - string of numbers readFileSync returns a buffer if you don't add an encoding.
data = JSON.parse(fs.readFileSync(`./system/index.json`, 'utf8'))