Unknown message when deleting bot messages
My message delete event throws me an error when i delete bot messages.
DiscordAPIError[10008]: Unknown Message
at handleErrors (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:730:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:1133:23)
at async SequentialHandler.queueRequest (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:963:14)
at async _REST.request (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:1278:22)
at async GuildMessageManager.edit (/workspace/Prismatic/node_modules/discord.js/src/managers/MessageManager.js:188:15) {
requestBody: {
files: [],
json: {
content: undefined,
tts: false,
nonce: undefined,
enforce_nonce: false,
embeds: undefined,
components: [],
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 0,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined,
applied_tags: undefined,
poll: undefined
}
},
rawError: { message: 'Unknown Message', code: 10008 },
code: 10008,
status: 404,
method: 'PATCH',
url: 'https://discord.com/api/v10/channels/1127359832685547702/messages/1263084219647660125'
} Promise {
<rejected> DiscordAPIError[10008]: Unknown Message
at handleErrors (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:730:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:1133:23)
at async SequentialHandler.queueRequest (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:963:14)
at async _REST.request (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:1278:22)
at async GuildMessageManager.edit (/workspace/Prismatic/node_modules/discord.js/src/managers/MessageManager.js:188:15) {
requestBody: { files: [], json: [Object] },
rawError: { message: 'Unknown Message', code: 10008 },
code: 10008,
status: 404,
method: 'PATCH',
url: 'https://discord.com/api/v10/channels/1127359832685547702/messages/1263084219647660125'
}
}
DiscordAPIError[10008]: Unknown Message
at handleErrors (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:730:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:1133:23)
at async SequentialHandler.queueRequest (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:963:14)
at async _REST.request (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:1278:22)
at async GuildMessageManager.edit (/workspace/Prismatic/node_modules/discord.js/src/managers/MessageManager.js:188:15) {
requestBody: {
files: [],
json: {
content: undefined,
tts: false,
nonce: undefined,
enforce_nonce: false,
embeds: undefined,
components: [],
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 0,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined,
applied_tags: undefined,
poll: undefined
}
},
rawError: { message: 'Unknown Message', code: 10008 },
code: 10008,
status: 404,
method: 'PATCH',
url: 'https://discord.com/api/v10/channels/1127359832685547702/messages/1263084219647660125'
} Promise {
<rejected> DiscordAPIError[10008]: Unknown Message
at handleErrors (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:730:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:1133:23)
at async SequentialHandler.queueRequest (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:963:14)
at async _REST.request (/workspace/Prismatic/node_modules/@discordjs/rest/dist/index.js:1278:22)
at async GuildMessageManager.edit (/workspace/Prismatic/node_modules/discord.js/src/managers/MessageManager.js:188:15) {
requestBody: { files: [], json: [Object] },
rawError: { message: 'Unknown Message', code: 10008 },
code: 10008,
status: 404,
method: 'PATCH',
url: 'https://discord.com/api/v10/channels/1127359832685547702/messages/1263084219647660125'
}
}
7 Replies
my code:
const { Events, EmbedBuilder, ChannelType, AuditLogEvent } = require('discord.js');
const Server = require('../Database/Server');
const { getEmojiURL } = require('../Modules/GetEmojiURL');
module.exports = {
name: Events.MessageDelete,
async execute(message) {
if (message.author.bot) { return }
const serverData = await Server.findOne({ Guild: message.guild.id })
if (serverData) {
if (serverData.MessageLog && serverData.MessageLog!= "") {
const logChannel = await message.guild.channels.fetch(serverData.MessageLog)
// const auditLogs = await message.guild.fetchAuditLogs({
// type: AuditLogEvent.MessageDelete,
// limit: 1,
// });
// const deletionLog = auditLogs.entries.first();
// const executor = deletionLog.executor;
// const deletionTimestamp = deletionLog.createdTimestamp;
// const currentTime = Date.now();
// let executorValue;
// if (Math.abs(deletionTimestamp - currentTime) < 1000) {
// executorValue = `${executor?? "*The executor could not be retrieved*"}`;
// } else {
// executorValue = "*Self Deletion*";
// }
await logChannel.send({
embeds: [
new EmbedBuilder()
.setAuthor({ name: "› Message Deleted", iconURL: await getEmojiURL(message.client, "1262303811201142805") })
.setDescription(`› The message send in ${message.channel} has been deleted.`)
.setFields(
{
name: "Message ID",
value: `\`${message.id}\``
},
{
name: "Message Author",
value: `${message.author ? `@${message.author.tag} (${message.author})`: "*The author could not be retrieved*"}`
},
{
name: "Deleted at",
value: `<t:${Math.floor(new Date().getTime() / 1000)}:R>`
},
{
name: "Message Content",
value: `${message.content?.length > 0? message.content : "*The content could not be retrieved*"}`
},
// {
// name: "Executor",
// value: executorValue
// }
)
.setColor("LightGrey")
]
})
}
}
}
}
const { Events, EmbedBuilder, ChannelType, AuditLogEvent } = require('discord.js');
const Server = require('../Database/Server');
const { getEmojiURL } = require('../Modules/GetEmojiURL');
module.exports = {
name: Events.MessageDelete,
async execute(message) {
if (message.author.bot) { return }
const serverData = await Server.findOne({ Guild: message.guild.id })
if (serverData) {
if (serverData.MessageLog && serverData.MessageLog!= "") {
const logChannel = await message.guild.channels.fetch(serverData.MessageLog)
// const auditLogs = await message.guild.fetchAuditLogs({
// type: AuditLogEvent.MessageDelete,
// limit: 1,
// });
// const deletionLog = auditLogs.entries.first();
// const executor = deletionLog.executor;
// const deletionTimestamp = deletionLog.createdTimestamp;
// const currentTime = Date.now();
// let executorValue;
// if (Math.abs(deletionTimestamp - currentTime) < 1000) {
// executorValue = `${executor?? "*The executor could not be retrieved*"}`;
// } else {
// executorValue = "*Self Deletion*";
// }
await logChannel.send({
embeds: [
new EmbedBuilder()
.setAuthor({ name: "› Message Deleted", iconURL: await getEmojiURL(message.client, "1262303811201142805") })
.setDescription(`› The message send in ${message.channel} has been deleted.`)
.setFields(
{
name: "Message ID",
value: `\`${message.id}\``
},
{
name: "Message Author",
value: `${message.author ? `@${message.author.tag} (${message.author})`: "*The author could not be retrieved*"}`
},
{
name: "Deleted at",
value: `<t:${Math.floor(new Date().getTime() / 1000)}:R>`
},
{
name: "Message Content",
value: `${message.content?.length > 0? message.content : "*The content could not be retrieved*"}`
},
// {
// name: "Executor",
// value: executorValue
// }
)
.setColor("LightGrey")
]
})
}
}
}
}
- 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!
- ✅
Marked as resolved by OPthat code doesn't match your error - the error is referencing code that tries to edit a message, your code only sends a message to a log channel.
do you have any other code that runs when a message is deleted?
This is the only code that uses the MessageDelete event
So you mean I should look for a code that tries to edit a message?
it happens when i delete the embed from this command. when i send it, restart and THEN delete, nothing happens.
but when i delete right after i send it, it throws an error in console
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } = require('discord.js');
const fs = require('node:fs');
const path = require('node:path');
const { getEmojiURL } = require('../../Modules/GetEmojiURL');
module.exports = {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Lists all commands.'),
async execute(interaction) {
const client = interaction.client
const commandsPath = path.join(__dirname, '../../Commands_Slash');
const commandFiles = fs.readdirSync(commandsPath, { recursive: true }).filter(file => file.endsWith('.js'));
const commands = commandFiles.map(file => {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
return { name: command.data.name, description: command.data.description };
});
const commandsPerPage = 5;
const totalPages = Math.ceil(commands.length / commandsPerPage);
let currentPage = 0;
async function generateEmbed(page) {
const start = page * commandsPerPage;
const end = start + commandsPerPage;
const embed = new EmbedBuilder()
.setAuthor({
name: "› Help",
iconURL: await getEmojiURL(interaction.client, "1263040971231465504"),
})
.setDescription("› Here are all the available commands:")
.setFooter({ text: `Page ${page + 1} of ${totalPages}` })
.setColor(0x00AE86)
.setImage(client.user.displayAvatarURL({dynamic: true, size: 1024}))
commands.slice(start, end).forEach(command => {
embed.addFields({ name: `/${command.name}`, value: `\`${command.description}\`` });
});
return embed;
};
const embedMessage = await interaction.reply({
embeds: [await generateEmbed(currentPage)],
components: [getRow(currentPage, totalPages)],
fetchReply: true
});
const collector = embedMessage.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 60000
});
collector.on('collect', async i => {
if (i.user.id !== interaction.user.id) {
return i.reply({ content: 'The buttons are disabled for you. To see all commands, do `/help`.', ephemeral: true });
}
if (i.customId === 'previous') {
currentPage = Math.max(currentPage - 1, 0);
} else if (i.customId === 'next') {
currentPage = Math.min(currentPage + 1, totalPages - 1);
}
await i.update({ embeds: [await generateEmbed(currentPage)], components: [getRow(currentPage, totalPages)] });
});
collector.on('end', collected => {
embedMessage.edit({ components: [] });
});
function getRow(page, total) {
return new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('previous')
.setLabel('Previous')
.setStyle(ButtonStyle.Primary)
.setDisabled(page === 0),
new ButtonBuilder()
.setCustomId('next')
.setLabel('Next')
.setStyle(ButtonStyle.Primary)
.setDisabled(page === total - 1)
);
}
},
};
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType } = require('discord.js');
const fs = require('node:fs');
const path = require('node:path');
const { getEmojiURL } = require('../../Modules/GetEmojiURL');
module.exports = {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Lists all commands.'),
async execute(interaction) {
const client = interaction.client
const commandsPath = path.join(__dirname, '../../Commands_Slash');
const commandFiles = fs.readdirSync(commandsPath, { recursive: true }).filter(file => file.endsWith('.js'));
const commands = commandFiles.map(file => {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
return { name: command.data.name, description: command.data.description };
});
const commandsPerPage = 5;
const totalPages = Math.ceil(commands.length / commandsPerPage);
let currentPage = 0;
async function generateEmbed(page) {
const start = page * commandsPerPage;
const end = start + commandsPerPage;
const embed = new EmbedBuilder()
.setAuthor({
name: "› Help",
iconURL: await getEmojiURL(interaction.client, "1263040971231465504"),
})
.setDescription("› Here are all the available commands:")
.setFooter({ text: `Page ${page + 1} of ${totalPages}` })
.setColor(0x00AE86)
.setImage(client.user.displayAvatarURL({dynamic: true, size: 1024}))
commands.slice(start, end).forEach(command => {
embed.addFields({ name: `/${command.name}`, value: `\`${command.description}\`` });
});
return embed;
};
const embedMessage = await interaction.reply({
embeds: [await generateEmbed(currentPage)],
components: [getRow(currentPage, totalPages)],
fetchReply: true
});
const collector = embedMessage.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 60000
});
collector.on('collect', async i => {
if (i.user.id !== interaction.user.id) {
return i.reply({ content: 'The buttons are disabled for you. To see all commands, do `/help`.', ephemeral: true });
}
if (i.customId === 'previous') {
currentPage = Math.max(currentPage - 1, 0);
} else if (i.customId === 'next') {
currentPage = Math.min(currentPage + 1, totalPages - 1);
}
await i.update({ embeds: [await generateEmbed(currentPage)], components: [getRow(currentPage, totalPages)] });
});
collector.on('end', collected => {
embedMessage.edit({ components: [] });
});
function getRow(page, total) {
return new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('previous')
.setLabel('Previous')
.setStyle(ButtonStyle.Primary)
.setDisabled(page === 0),
new ButtonBuilder()
.setCustomId('next')
.setLabel('Next')
.setStyle(ButtonStyle.Primary)
.setDisabled(page === total - 1)
);
}
},
};
Thanks.
works now