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});
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});
2 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Parogo_72
Parogo_722y ago
fetch the message using channel.messages.fetch(id) and handle the promise
Want results from more Discord servers?
Add your server