switch statement not triggering in catch function

Hi, I'm trying to handle errors when trying to fetch a message but it just doesn't run the switch statement. Does someone have an idea why?
const msg = await channel.messages.fetch(serverConfig.ticketMessage.id).catch(e => {
console.log("Error", e.status); // gets logged
switch (e.status) {
case 404:
interaction.reply({ content: `The message could not be edited. It may have been deleted.` }); // does not get logged
return;
case 403:
interaction.reply({ content: `The message could not be edited. I don't have access to the channel.` }); // does not get logged
return;
default:
console.log("Test"); // does not get logged
break;
}
console.log("Test 2"); // does not get logged
});
const msg = await channel.messages.fetch(serverConfig.ticketMessage.id).catch(e => {
console.log("Error", e.status); // gets logged
switch (e.status) {
case 404:
interaction.reply({ content: `The message could not be edited. It may have been deleted.` }); // does not get logged
return;
case 403:
interaction.reply({ content: `The message could not be edited. I don't have access to the channel.` }); // does not get logged
return;
default:
console.log("Test"); // does not get logged
break;
}
console.log("Test 2"); // does not get logged
});
5 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Kinect3000
Kinect30003y ago
Can you add a log in each case?
ncls.
ncls.OP3y ago
I didn't think about that. It actually logs. But why doesn't it reply?
Kinect3000
Kinect30003y ago
It doesn’t happen often that you reply in time after making an api call You should deferReply beforehand, then editReply when ur ready to respond You can check if this is the issue by catching the reply calls
ncls.
ncls.OP3y ago
When I do
interaction.reply({ content: `The message could not be edited. It may have been deleted.` }).catch(e => console.log(e));
interaction.reply({ content: `The message could not be edited. It may have been deleted.` }).catch(e => console.log(e));
It doesn't do anything The slash command interaction from the user
Want results from more Discord servers?
Add your server