最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Discord Bot send message without command - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 4

Get 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;
});
发布评论

评论列表(0)

  1. 暂无评论