'How to ignore msg.delete() if not found discord.js
execute(client, message) {
message.channel.send(`Last heartbeat calculated ${ms(Date.now() - client.ws.shards.first().lastPingTimestamp, { long: true })} ago **${client.ws.ping}ms** 🛰️`).then(msg => {
setTimeout(() => msg.delete(), client.config.app.dtime)
});
Hi there, I was working on my discord bot and ran into a scenario like this, the code causing the problem is shown above. When this function runs, it sends the current ping of the bot to the message channel. and automatically deletes the msg after some time, but in case some person with admin privileges deletes the message manually. My bot will crash when it tries to delete so to avoid that how should I fix my code. Thanks in advance.
Solution 1:[1]
Try going to your index file where you start the bot, and do this line
process.on("uncaughtException", (error) => {
console.log(error)
})
It will console log an error, and won't crash, and also every time your bot is about to crash, it will just console it :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Skayu |
