#TypeError: Cannot read properties of null (reading 'bot')

9 messages · Page 1 of 1 (latest)

charred citrusBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
elder jewel
#
const { checkIfCountingChannelWithChannel, updateCurrentCount } = require("../database/dbFunctions.js");
const math = require('mathjs');
module.exports = {
    name: 'messageDelete',
    async execute(message, client) {
        if (message.author.bot) {
            return;
        }
    }
}```

Problem: Whenever a message gets deleted thats send before the bot is online the code crashes
#
const { Client, GatewayIntentBits, Collection, Partials } = require('discord.js');
const client = new Client({ 
    intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildVoiceStates, 
        GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessageReactions ],
    partials: [Partials.Message, Partials.Channel, Partials.Reaction]
 
});```

partials and other sutff
broken ether
#

Yes, if the message was not cached then author will be null (because discord only sends the id in messageDelete event, nothing else). So either check for message.partial first or use optional chaining

elder jewel
#

Ah, so if the message is partial, it wont show the author unless i cache it first

broken ether
#

You can’t cache it anymore when it already got deleted. If it‘s partial you only have the ids, nothing else

elder jewel
broken ether
#

Correct