簡體   English   中英

Discord.JS 機器人沒有響應

[英]Discord.JS bot does not respond

我的 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');

控制台中沒有錯誤。 控制台中唯一的消息是“准備就緒!”。 我還檢查了是否安裝了 Discord.JS NPM 模塊,它是。

為了使您的機器人能夠在收到消息時執行某些操作,您需要使用client.on('message',message =>{//your code}

例子:

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

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

您需要觸發一個事件。 在這種情況下,您希望它回復。 所以你需要消息事件。

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

    //This is where your function would go
    //

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM