[英]Discord.JS bot does not respond
My Discrod.JS bot is online but not responding.我的 Discrod.JS 机器人在线但没有响应。 This is the code-
这是代码-
// require the discord.js module
const Discord = require('discord.js');
// create a new Discord client
const client = new Discord.Client();
// when the client is ready, run this code
// this event will only trigger one time after logging in
client.once('ready', () => {
console.log('Ready!');
});
module.exports = function(controller) {
controller.hears(
"!appreciates",
["direct_mention", "mention"],
(bot, message) => {
let response;
let sender = message.user;
let recipient = message.mentions.users
.filter(user => user.bot === false)
.last();
let responses = [
`Hey, ${sender}, I appreciate you! :heart_eyes:`,
`Hey, ${sender}, I appreciate your enthusiasm! :muscle:`,
`Hey, ${sender}, I appreciate your commands! :wink:`,
`Hey, ${sender}, I appreciate your particaption! :grinning:`,
`Hey, ${sender}, I appreciate all your works! :blush:`,
`Hey, ${sender}, I appreciate everything you do. :star_struck:`
];
response = responses[Math.floor(Math.random() * responses.length)];
bot.reply(message, response);
}
);
};
client.login('app token');
There is no error in the console.控制台中没有错误。 The only message in the console is "Ready!".
控制台中唯一的消息是“准备就绪!”。 I have also checked if Discord.JS NPM module is installed and it is.
我还检查了是否安装了 Discord.JS NPM 模块,它是。
To make your bot be able to do something when receiving a message you need client.on('message',message =>{//your code}
为了使您的机器人能够在收到消息时执行某些操作,您需要使用
client.on('message',message =>{//your code}
example:例子:
client.on('message',message =>{
//execute a command
message.channel.send("hello world");
});
You need an event to be triggered.您需要触发一个事件。 In this case, you want it to reply.
在这种情况下,您希望它回复。 So you need the message event.
所以你需要消息事件。
bot.on('message', message => {
//
//This is where your function would go
//
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.