hey I create a offline notifer as event

But if my bot get offline I get no notification any idea why?
const { Events, EmbedBuilder} = require('discord.js');

module.exports = {

name: Events.PresenceUpdate,

async execute (oldStatus, newStatus, client) {

if (newStatus.user.id !== "xxx") return;

var bot = await client.users.fetch("xxx");

async function sendMessage (message) {

const embed = new EmbedBuilder()


.setColor("Blurple")

.setDescription(message);

var channel = await client.channels.fetch("xxx");

var member = await client.users.fetch("xxx");

await channel.send({ embeds: [embed] }).catch(err => {});

await member.send({ embeds: [embed] }).catch(err => {});

}

var timestamp = `<t:$(Math.floor(Date.now()/1000)):R>`;

if (!oldStatus && newStatus.status !== "offline") {

await sendMessage(`:warning: **Looks like ${bot.username} is offline!**\n${bot.username} (${bot.id}) became offline ${timestamp}, you might need to turn it back on to resolve this issue.`);
} else if (oldStatus.status !== "offline" && newStatus.status == "offline"){

await sendMessage(`:information_source: **${bot.username} is back online!**\n${bot.username} (${bot.id}) was recently offline and as of now (${timestamp}) is back online!`);
}
}
}
const { Events, EmbedBuilder} = require('discord.js');

module.exports = {

name: Events.PresenceUpdate,

async execute (oldStatus, newStatus, client) {

if (newStatus.user.id !== "xxx") return;

var bot = await client.users.fetch("xxx");

async function sendMessage (message) {

const embed = new EmbedBuilder()


.setColor("Blurple")

.setDescription(message);

var channel = await client.channels.fetch("xxx");

var member = await client.users.fetch("xxx");

await channel.send({ embeds: [embed] }).catch(err => {});

await member.send({ embeds: [embed] }).catch(err => {});

}

var timestamp = `<t:$(Math.floor(Date.now()/1000)):R>`;

if (!oldStatus && newStatus.status !== "offline") {

await sendMessage(`:warning: **Looks like ${bot.username} is offline!**\n${bot.username} (${bot.id}) became offline ${timestamp}, you might need to turn it back on to resolve this issue.`);
} else if (oldStatus.status !== "offline" && newStatus.status == "offline"){

await sendMessage(`:information_source: **${bot.username} is back online!**\n${bot.username} (${bot.id}) was recently offline and as of now (${timestamp}) is back online!`);
}
}
}
12 Replies
d.js toolkit
d.js toolkitβ€’3w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
chewie 🌈
chewie πŸŒˆβ€’3w ago
how do you expect your bot to receive stuff if its offline?
monbrey
monbreyβ€’3w ago
Because its offline?
Nicolas Matheisen
Nicolas Matheisenβ€’3w ago
If I turn it of the bot need 2 min to truely get off and I found a video how it get but in my chase it doesn't work and I don't understand why
Nicolas Matheisen
Nicolas Matheisenβ€’3w ago
MrJAwesome
YouTube
[NEW] - OFFLINE BOT NOTIFICATION system for your Discord Bot! || Di...
This is how you can notify developers when your bot goes offline using a discord bot! Join my discord: 👺 https://discord.gg/E6AJ7eNrsd Want to become a member? Want access to pastebins? Join below! 👺 https://www.youtube.com/channel/UC3JG-y_RtMszRFkdxUrrEEQ/join Invite my new project! (Automate): 👺 https://discord.com/api/oauth2/authorize?clie...
Nicolas Matheisen
Nicolas Matheisenβ€’3w ago
I hope it's no advertisement
chewie 🌈
chewie πŸŒˆβ€’3w ago
thats just discord being discord, your bot is truly offline as soon as you stop it
Nicolas Matheisen
Nicolas Matheisenβ€’3w ago
hmmm ok and what do the dude in the videoπŸ˜‚πŸ˜… I am confused
chewie 🌈
chewie πŸŒˆβ€’3w ago
thats a second bot sending a message when the other bot goes offline
Nicolas Matheisen
Nicolas Matheisenβ€’3w ago
xD ufff lol ahhh thats the secret 🀯🀯🀯 Ty I try to find another way
h4ze
h4zeβ€’3w ago
Why not just let your bot query? e.g. via bash script which checks every few minutes whether the process is still running and if not, should the bash script send a message to you? via webhook and telegram .. or pushover btw I think you can even check via the discord api if your bot is online or offline.. Like a normal user
Nicolas Matheisen
Nicolas Matheisenβ€’3w ago
ufff I don't know how πŸ˜… do u have a youtube video?