Message fetching

I have this function which edits a message anytime it is called, or re-sends it if it was deleted. I have noticed that when I restart the bot, it won't recognize the message and resend it, then start editing the new message. What is the cause of this and how can I fix it?

const settings = mongoose.model('Settings');

const ids = await settings.findOne({name: "updatedReport"});
const channelID = ids ? ids.value.split("-")[0] : config.updateReportRoom;
const channel = client.guilds.cache.get(config.guildID).channels.cache.get(channelID);
if (!channel) return;

const embeds = await msg(client);
let message;

if (ids) {
  const messageID = ids.value.split("-")[1];
  message = await channel.messages.cache.get(messageID);
  if (!message) {
    message = await channel.send("Working...");
    ids.value = channelID + "-" + message.id;
    await ids.save();
  }
}
else {
  message = await channel.send("Working...");
  const doc = new settings();
  doc.name = "updatedReport";
  doc.value = channelID + "-" + message.id;
  await doc.save();
}
        
message.edit({content: "", embeds: embeds});
Was this page helpful?