message.edit is not a function

I'm developing a simple Discord bot for my classmates to manage homework assignments. The bot sends homework details as embeds. However, when I attempt to edit an existing homework embed using a button interaction and modal, I encounter the following error:​ /home/matt/School/homeworkBot/responses/edit.js:84 await message.edit({embeds: [updatedEmbed], components: message.components}); ^ TypeError: message.edit is not a function at Statement.<anonymous> (/home/matt/School/homeworkBot/responses/edit.js:84:39) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) Node.js v18.19.0 Code Snippet:
const message = await channel.messages.fetch(row[0].message_id, { force: true });
console.log(message);
//outputs Collection(1) [Map] {
// '1367168748129357935' => <ref *1> Message {
// channelId: '1366858248614969465',
// guildId: '1366489027154284604',
// id: '1367168748129357935',
// ETC, the entire object seems fine
await message.edit({embeds: [updatedEmbed], components: message.components});
await interaction.reply({
content: ':white_check_mark: Úkol byl úspěšně upraven.',
ephemeral: true,
});
const message = await channel.messages.fetch(row[0].message_id, { force: true });
console.log(message);
//outputs Collection(1) [Map] {
// '1367168748129357935' => <ref *1> Message {
// channelId: '1366858248614969465',
// guildId: '1366489027154284604',
// id: '1367168748129357935',
// ETC, the entire object seems fine
await message.edit({embeds: [updatedEmbed], components: message.components});
await interaction.reply({
content: ':white_check_mark: Úkol byl úspěšně upraven.',
ephemeral: true,
});
Additional Information: The message_id is retrieved from a database and corresponds to a message previously sent by the bot. The bot has Administrator permissions. The console.log(message); line outputs a valid Message object, indicating that the message is successfully fetched.​ Troubleshooting Steps Taken: Verified that the message is sent by the bot. Confirmed that channel is a valid TextChannel instance. Ensured that updatedEmbed is a properly constructed Embed object. Checked that message.components is an array of MessageActionRow components.​ Request: I'm seeking assistance in identifying why message.edit is not recognized as a function, despite the message object appearing valid. Any insights or suggestions would be greatly appreciated.
4 Replies
d.js toolkit
d.js toolkit14h 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! - Marked as resolved by OP
MatheX
MatheXOP14h ago
node 18.19 discord.js 14.19.2
Amgelo
Amgelo14h ago
- fetch takes a single argument, not two, the force is being ignored - the log says it's a collection, not a message, so indeed there's no .edit() on it - messages.fetch will only return a collection if you don't pass anything to it, and then it'll try to fetch the last 100 messages, so it sounds like row[0].message_id is undefined, and the channel only has a single message
MatheX
MatheXOP14h ago
yep solved it, the message_id is stored as INTIGER in sqlite and the int overflows to another message id so the message couldnt have been puld so it infact returned collection instead of message, sometimes all it takes is a bit of lead from somebody else, thanks.

Did you find this page helpful?