My Discrod.JS bot is online but not responding. 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.
To make your bot be able to do something when receiving a message you need 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
//
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.