Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Discord Bot Issue - TypeError: Cannot read properties of null (reading 'id')

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
        }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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'))
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!