How to fix 'Cannot read property 'id' of 'null'

how to fix anything
how to fix a zipper
how to fix phone
how to fix things
how to fix things around the house
how to fix keyboard
how to fix a computer
how to repair appliances

I have this error message that comes in from time to time that crashes my bot. Here is the error message in the console:

C:\Users\Administrator\Desktop\FortniteRanked8.5\events\message.js:7
  if(prefixed.hasOwn(message.guild.id)){
                                   ^

TypeError: Cannot read property 'id' of null
    at module.exports (C:\Users\Administrator\Desktop\FortniteRanked8.5\events\message.js:7:36)

The problem comes from this line:

if (prefixes.hasOwn(message.guild.id)){

Setup:

  • Windows server 2012
  • Discord.js : v11.4.2
  • node : v8.11.1

Code:

const Store = require('data-store');

module.exports = (client, message) => {
  var prefixes = new Store({ path: __dirname + '/../prefixes.json' });
  // console.log(prefixes.clone())

  if (message.author.bot) return;

  var prefix = client.config.prefix

  if (prefixes.hasOwn(message.guild.id)){
    prefix = prefixes.get(message.guild.id)
  }

  if (message.content.indexOf(prefix) !== 0) return;

  const args = message.content.slice(prefix.length).trim().split(/ +/g);
  const command = args.shift().toLowerCase();
  const cmd = client.commands.get(command);

  if (!cmd) return;

  if (cmd && !message.guild)
    return message.channel.send("Vous ne pouvez pas faire de commande ici, Merci de faire les commandes directement sur votre serveur discord.");

  cmd.run(client, message, args);
};

message.guild is null, before you should check if it exists like message && message.guild && .... Using this you’ll be sure that all the fields exist.

How to Fix Everything, Umbra visits the Fixers' Collective in Brooklyn, a social experiment in improvisational fixing Duration: 2:53 Posted: 9 Mar 2010 Here's how: 1. Navigate to the Windows 10 Advanced Startup Options menu. On many laptops, hitting F11 as soon as you power on will 2. Click Startup Repair.

Check guild before use it

if(message.guild && prefixes.hasOwn(message.guild.id))

28 HACKS TO FIX ANYTHING QUICKLY, holes in plywood, how to unscrew a rusty screw, how to drill a hole in the wood, and other tricks Duration: 9:51 Posted: 10 Nov 2018 iFixit is a global community of people helping each other repair things. Let's fix the world, one device at a time. Troubleshoot with experts in the Answers forum—and build your own how-to guides to share with the world.

The Guild object you're accessing doesn't exist. So it has no id member in it. So it says, TypeError: Cannot read property 'id' of null. Thanks to all other users contributed.

More at MDN about TypeError.

The solution

You need to check whether the guild you're accessing does even exist or not?. For that you need to check the guild's avialable property.

/* Check the evidence of guild's existance */
if(message.guild.avialable === true && prefixes.hasOwn(message.guild.id))

Repair Manuals for Every Thing, Thousands of repair manuals, tutorials, and how-to guides for DIY fixes. From electronics to cars, learn how to repair your own stuff and save yourself some  FIX.com - Helping Anyone FIX Anything: Home Hacks, Lifestyle Tips, Repair Help, and MORE! 6,093 views 1 year ago SUBSCRIBE to our Channel for Help FIXing your Appliances, Power Tools and Outdoor

If the error message says "Could not read property 'id' of null" it means that the guild property exists, but it is null. As it has been previously said, you have to check it, but besides that you have to check: why does guild be null?

In case there was no property you would get "Could not read property 'id' of undefined" as the error.

iFixit: The Free Repair Manual, iFixit is a global community of people helping each other repair things. Let's fix the world, one device at a time. Troubleshoot with experts in the Answers  Microsoft Easy Fix solutions have been discontinued Content provided by Microsoft Applies to: Windows 10, version 1809, all editions Windows 10, version 1803, all editions Windows 10, version 1709, all editions Windows 10, version 1703, all editions Windows 10, version 1607, all editions Windows 8.1 Windows 8 Windows 7 Enterprise Windows 7 Home

100 Home Repairs You Can Do Yourself, How to Fix Roof Vents. Check for cracked housings on plastic roof vents and broken seams on metal ones. You might be tempted to throw caulk at the problem,  Repairing nasty leather or vinyl seating. This repair will last you for years and years. This video shows you how to fix cracks and rips in your upholstery and then recolor them to be perfect again.

12 Easy Things Everyone Should Know How to Fix, Whether you are new homeowner or an expert, knowing how to fix these 12 common household problems can help save you from a pricey  To fix a bad credit score, understand the basic contributors to credit—including whether you pay your bills on time and whether you carry balances on credit cards—and identify the factors that are making a negative impact.

How to Repair, Fix It Yourself. Do your own home repairs with easy step-by-step instructions. do it yourself tools and supplies ©Kurhan / Shutterstock 

Comments
  • Thank you indeed I did not think about it.
  • Thank you very much for your very fast answer I will do the test, I will inform you of the news
  • Thank you very much for the explanation !