Discord.JS机器人没有响应

时间:2020-09-19 13:44:23

标签: javascript node.js discord.js

我的Discrod.JS机器人在线,但没有响应。这是代码-

// 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');

控制台中没有错误。控制台中唯一的消息是“ Ready!”。我还检查了Discord.JS NPM模块是否已安装。

2 个答案:

答案 0 :(得分:1)

要使您的机器人能够在收到消息时执行某些操作,您需要 client.on('message',message =>{//your code}

示例:

client.on('message',message =>{

//execute a command
message.channel.send("hello world");
});

答案 1 :(得分:0)

您需要触发一个事件。在这种情况下,您希望它回复。所以你需要消息事件。

bot.on('message', message => {
    //

    //This is where your function would go
    //

});