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;
}

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?
Was this page helpful?