- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - 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!
#TypeError: Cannot read properties of null (reading 'bot')
9 messages · Page 1 of 1 (latest)
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
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
I'd assume thats just message.partial ?
Ah, so if the message is partial, it wont show the author unless i cache it first
You can’t cache it anymore when it already got deleted. If it‘s partial you only have the ids, nothing else
ah, so if the message isnt cached and i delete it then theres no way for me to retrieve the message author Id ?
Correct