messageDelete does not work with old messages.

If I delete a message that I just sent or that I sent a few minutes/hours ago, the bot detects and sends the embed but if I delete an old one, it doesn't work..
12 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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!
Aiwoz[old]
Aiwoz[old]OP9mo ago
If I delete a message that I just sent or that I sent a few minutes/hours ago, the bot detects and sends the embed but if I delete an old one, it doesn't work.. messageDelete.js :
const { EmbedBuilder } = require(`discord.js`);

module.exports = {
name: `messageDelete`,
description: `Événement lorsqu'un message est supprimé du serveur.`,
async execute(message) {

const messageLog = new EmbedBuilder()
.setColor(`#4CE1FE`)
.setTitle(`__Un Message a été supprimé :__`)
.setDescription(`**Message :** \n ${message.content} \n **ID du message :** ${message.id} \n **Salon :** <#${message.channel.id}> \n **Par :** ${message.author.displayName} \n **ID :** ${message.author.id}`)
.setTimestamp();
if (message.attachments.size > 0) {
const mediaUrls = message.attachments.map(attachment => attachment.url);
messageLog.setDescription(`**Message :** \n ${message.content} \n **ID du message :** ${message.id} \n **Salon :** <#${message.channel.id}> \n **Par :** ${message.author.displayName} \n **ID :** ${message.author.id} \n **Médias :** \n` + mediaUrls.join('\n'));
}
message.guild.channels.cache.get("1190563847224954980").send({embeds: [messageLog]});

}
}
const { EmbedBuilder } = require(`discord.js`);

module.exports = {
name: `messageDelete`,
description: `Événement lorsqu'un message est supprimé du serveur.`,
async execute(message) {

const messageLog = new EmbedBuilder()
.setColor(`#4CE1FE`)
.setTitle(`__Un Message a été supprimé :__`)
.setDescription(`**Message :** \n ${message.content} \n **ID du message :** ${message.id} \n **Salon :** <#${message.channel.id}> \n **Par :** ${message.author.displayName} \n **ID :** ${message.author.id}`)
.setTimestamp();
if (message.attachments.size > 0) {
const mediaUrls = message.attachments.map(attachment => attachment.url);
messageLog.setDescription(`**Message :** \n ${message.content} \n **ID du message :** ${message.id} \n **Salon :** <#${message.channel.id}> \n **Par :** ${message.author.displayName} \n **ID :** ${message.author.id} \n **Médias :** \n` + mediaUrls.join('\n'));
}
message.guild.channels.cache.get("1190563847224954980").send({embeds: [messageLog]});

}
}
Ex : A messaexample: a message dated March 5.
mallusrgreat
mallusrgreat9mo ago
it doesn't work with uncached messages, you'd have to enable the partial if you still want to receive a message with just its id
Aiwoz[old]
Aiwoz[old]OP9mo ago
How to make this ?
d.js docs
d.js docs9mo ago
:guide: Popular Topics: Partial Structures - Enabling Partials read more
Aiwoz[old]
Aiwoz[old]OP9mo ago
Thank you but i have an error too.
const { EmbedBuilder } = require(`discord.js`);

module.exports = {
name: `messageDelete`,
description: `Événement lorsqu'un message est supprimé du serveur.`,
async execute(message) {

if (message.partial) {
message.fetch()
.then(fullMessage => {
console.log(fullMessage.content);
})
.catch(error => {
console.log('Something went wrong when fetching the message: ', error);
});
} else {
const messageLog = new EmbedBuilder()
.setColor(`#4CE1FE`)
.setTitle(`__Un Message a été supprimé :__`)
.setDescription(`**Message :** \n ${message.content} \n **ID du message :** ${message.id} \n **Salon :** <#${message.channel.id}> \n **Par :** ${message.author.displayName} \n **ID :** ${message.author.id}`)
.setTimestamp();
if (message.attachments.size > 0) {
const mediaUrls = message.attachments.map(attachment => attachment.url);
messageLog.setDescription(`**Message :** \n ${message.content} \n **ID du message :** ${message.id} \n **Salon :** <#${message.channel.id}> \n **Par :** ${message.author.displayName} \n **ID :** ${message.author.id} \n **Médias :** \n` + mediaUrls.join('\n'));
}
message.guild.channels.cache.get("1190563847224954980").send({embeds: [messageLog]});
}
}
}
const { EmbedBuilder } = require(`discord.js`);

module.exports = {
name: `messageDelete`,
description: `Événement lorsqu'un message est supprimé du serveur.`,
async execute(message) {

if (message.partial) {
message.fetch()
.then(fullMessage => {
console.log(fullMessage.content);
})
.catch(error => {
console.log('Something went wrong when fetching the message: ', error);
});
} else {
const messageLog = new EmbedBuilder()
.setColor(`#4CE1FE`)
.setTitle(`__Un Message a été supprimé :__`)
.setDescription(`**Message :** \n ${message.content} \n **ID du message :** ${message.id} \n **Salon :** <#${message.channel.id}> \n **Par :** ${message.author.displayName} \n **ID :** ${message.author.id}`)
.setTimestamp();
if (message.attachments.size > 0) {
const mediaUrls = message.attachments.map(attachment => attachment.url);
messageLog.setDescription(`**Message :** \n ${message.content} \n **ID du message :** ${message.id} \n **Salon :** <#${message.channel.id}> \n **Par :** ${message.author.displayName} \n **ID :** ${message.author.id} \n **Médias :** \n` + mediaUrls.join('\n'));
}
message.guild.channels.cache.get("1190563847224954980").send({embeds: [messageLog]});
}
}
}
Something went wrong when fetching the message: DiscordAPIError[10008]: Unknown Message at handleErrors (C:\Users\Aiwoz\Desktop\Bot Discord\Bot-Aiwoz\node_modules@discordjs\rest\dist\index.js:722:13) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async SequentialHandler.runRequest (C:\Users\Aiwoz\Desktop\Bot Discord\Bot-Aiwoz\node_modules@discordjs\rest\dist\index.js:1120:23) at async SequentialHandler.queueRequest (C:\Users\Aiwoz\Desktop\Bot Discord\Bot-Aiwoz\node_modules@discordjs\rest\dist\index.js:953:14) at async _REST.request (C:\Users\Aiwoz\Desktop\Bot Discord\Bot-Aiwoz\node_modules@discordjs\rest\dist\index.js:1266:22) at async GuildMessageManager._fetchSingle (C:\Users\Aiwoz\Desktop\Bot Discord\Bot-Aiwoz\node_modules\discord.js\src\managers\MessageManager.js:107:18) { requestBody: { files: undefined, json: undefined }, rawError: { message: 'Unknown Message', code: 10008 }, code: 10008, status: 404, method: 'GET', url: 'https://discord.com/api/v10/channels/1190031214942376067/messages/1209197420735496253' }
mallusrgreat
mallusrgreat9mo ago
you can't fetch a deleted message
Aiwoz[old]
Aiwoz[old]OP9mo ago
Yes but what is the utility of partials ?
mallusrgreat
mallusrgreat9mo ago
it will send you the event even if the item isn't cached
Aiwoz[old]
Aiwoz[old]OP9mo ago
Okay, but it is not possible to retrieve one of the following elements: Author of the message, content, reaction. ?
NyR
NyR9mo ago
Author maybe perhaps, if the message was deleted by someone other the the message author (by getting it from audit log) and that's a big if, but other things, no
Aiwoz[old]
Aiwoz[old]OP9mo ago
Thank you. ^^
Want results from more Discord servers?
Add your server