discord.js bot消息和数组响应

时间:2020-05-05 18:24:16

标签: javascript bots discord discord.js

基本上,我试图让我的discord.js v12.0.0机器人响应某些单词,并且单词和响应位于数组中。我似乎收到此错误:TypeError: Cannot read property 'split' of undefined

const Discord = require("discord.js");
const client = new Discord.Client();
const message = new Discord.Message();

var messages = ['ayy','stop','ok','wait','help'];
var responses = ['Ayy','stop','ok','i am sorry','you getting nothing'];
var content = message.content.split(' ');

client.on("message", (message) => {
    if (message.content.includes(responseObject[message.content])) {
        message.channel.send(responseObject[message.content]);
    }
  });

2 个答案:

答案 0 :(得分:0)

那是因为您需要将var content = message.content.split(' ');放在message事件中

并摆脱const message = new Discord.Message();

答案 1 :(得分:-1)

var names = [
  "**Bill Gates**: ",
  "**Ken Kaneki**: ",
  "**Steve Jobs**: ",
  "**Joe Mama**: ",
  "**Lonely hobo on the streets**: "
]

var answers = [
  "Ok buddy, now get da hell 'outta here.",
  "Begone, thot",
  "What? U want money? Naa bro, u just gonna use it to buy weed",
  "No parents.",
  "Naa fam"
]
var randomAnswer = names[Math.floor(Math.random() * names.length)] + answers[Math.floor(Math.random() * answers.length)]
console.log(randomAnswer);