I have some code that runs in the background, 24/7, in JavaScript of course. I'd like to set a discord.js bot to output a message if something (like an errror) happens on the code that is constantly running.
How do you send a message to any channel without listening for a messagge? All the tutorials create mands that rely on COMMAND to make the bot "reply" to you. I want the bot to be the one sending the first message, and reading back my response and acting accordingly.
I'm currently using the discord.js node library (/).
Is this possible?
I have some code that runs in the background, 24/7, in JavaScript of course. I'd like to set a discord.js bot to output a message if something (like an errror) happens on the code that is constantly running.
How do you send a message to any channel without listening for a messagge? All the tutorials create mands that rely on COMMAND to make the bot "reply" to you. I want the bot to be the one sending the first message, and reading back my response and acting accordingly.
I'm currently using the discord.js node library (https://discord.js/).
Is this possible?
Share Improve this question edited Mar 27, 2018 at 14:17 André 4,4974 gold badges33 silver badges58 bronze badges asked Sep 20, 2017 at 9:57 Gal AppelbaumGal Appelbaum 1,9556 gold badges21 silver badges33 bronze badges1 Answer
Reset to default 4Get the list of channels from the channel cache by name, and add an event listener for the error
event to window. When an error is detected, send a message to the channel:
var client = new Discord.Client();
var channel = client.channels.get('name', nameOfChannel); // or client.channels.get("the channel id")
window.addEventListener('onError', function(e) {
channel.send(e.error.message) // or client.sendMessage(channel, e.error.message) in older versions;
});