Message cannot be edited

My code:
// The channel is fetched with ctx.guild.channels.fetch(parsedLink.channelId)
let message: Message | null = null;
try {
message = await channel.messages.fetch(parsedLink.messageId);
// Validate message and stuff, but not important.
} catch (err) {
console.error(inspect(err));
return;
}

let data = {
action: "edit",
where: message,
};

setCacheData(ctx.guildId, ctx.user.id, data);

// Later, in another function

/*
- panelData.action can only be "edit" or "send"
- panelData.where is a message when panelData.action is "edit" ; a Text-/NewsChannel when panelData.action is "send"
- messageArgs is of type MessageEditOptions
*/

let panel: Message;
try {
if (panelData.action == "edit") {
panel = await panelData.where.edit(messageArgs); // panelData.where is a Message
} else {
panel = await panelData.where.send(messageArgs); // panelData.where is a Text or NewsChannel
}
} catch (err) {
await ctx.reply({
embeds: [
{
title: `Panel not ${panelData.where instanceof Message ? "edited" : "sent"}`,
description: `${err}`,
color: 0xff0000,
},
],
});
return;
}
// The channel is fetched with ctx.guild.channels.fetch(parsedLink.channelId)
let message: Message | null = null;
try {
message = await channel.messages.fetch(parsedLink.messageId);
// Validate message and stuff, but not important.
} catch (err) {
console.error(inspect(err));
return;
}

let data = {
action: "edit",
where: message,
};

setCacheData(ctx.guildId, ctx.user.id, data);

// Later, in another function

/*
- panelData.action can only be "edit" or "send"
- panelData.where is a message when panelData.action is "edit" ; a Text-/NewsChannel when panelData.action is "send"
- messageArgs is of type MessageEditOptions
*/

let panel: Message;
try {
if (panelData.action == "edit") {
panel = await panelData.where.edit(messageArgs); // panelData.where is a Message
} else {
panel = await panelData.where.send(messageArgs); // panelData.where is a Text or NewsChannel
}
} catch (err) {
await ctx.reply({
embeds: [
{
title: `Panel not ${panelData.where instanceof Message ? "edited" : "sent"}`,
description: `${err}`,
color: 0xff0000,
},
],
});
return;
}
Versions - discord.js: 14.17.3 - npm: 11.0.0 - Typescript: 5.2.6 - node: 22.13.0 LTS I always get the error, that the edition of the panel failed. Does anyone have an idea what's wrong here? -# This post is the continuation of https://github.com/discordjs/discord.js/issues/10700
12 Replies
d.js toolkit
d.js toolkit5d 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
LukeZ
LukeZOP5d ago
yeah, it's a Message object uuuh, not now - I can show it later since I'm not at my pc. okay, I now have the message object here. Got it with inspect(panelData.where) the client is just missing lol I will try to replicate it with another bot. nope, I didn't. give me a moment, I'll try well, I couldn't replicate it so I will try something else. I now did a npm ci. testing again... well, client wasn't found - it's undefined. I will build in logging statements to trace where the client is lost.
LukeZ
LukeZOP5d ago
okay, as it turns out - the client is there after the fetch, and after the cache data gets initialized. (img 1) But right when I retrieve it the next time, it's gone. (img 2)
No description
No description
NyR
NyR5d ago
Well, there's your issue then. Object.assign only copies the enumerable properties. <Message>.client is not enumerable
d.js docs
d.js docs5d ago
:mdn: Object.assign() The Object.assign() static method copies all enumerable own properties from one or more source objects to a target object. It returns the modified target object.
LukeZ
LukeZOP5d ago
bruh... but what can I do to fix this then?
NyR
NyR5d ago
Do not use it? Why do you even need to use it? From the looks of it, you are assigning it to an empty object, why not simply return it as is?
LukeZ
LukeZOP5d ago
wdym? oh, you mean I should just modify the original data instead of assigning it? OR could I just do this?
let newData = { ...originalData };
let newData = { ...originalData };
NyR
NyR5d ago
I'm not sure what you are hoping to achieve by doing this Object.assign({}, cachedData)
LukeZ
LukeZOP5d ago
well... I also don't 😂 I may have forgot to make a comment why I I decided to do this back then haha
NyR
NyR5d ago
You can just do this then ^
LukeZ
LukeZOP5d ago
okay, well I think I have to refactor this logic then xD Thanks to y'all 😄 it was it was logged as Message { ... } that's the funny part uhm, this one was logged when the error was thrown when trying to edit the message. Okay, I've now followed the advice and didn't create new instances every time. I think the issue is the NodeCache library but I have to test that. Update: HA. That's it. The client prop exceeds some limit in the caching library I guess. I will find a solution for by myself :)

Did you find this page helpful?