admin管理员组文章数量:1390906
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;
});
本文标签: javascriptDiscord Bot send message without commandStack Overflow
版权声明:本文标题:javascript - Discord Bot send message without command - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744596386a2614803.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论