简体   繁体   English

为什么我的 discord.js bot 没有响应“;say (content)”

[英]Why is my discord.js bot not responding to ";say (content)"

I am coding a bot on discord called LowerBot, it is made in javascript and is using npm and discord.js.我正在编写一个名为 LowerBot 的 Discord 机器人,它是用 javascript 制作的,并且使用的是 npm 和 discord.js。 If somebody can pinpoint exactly where my bot went wrong that would be nice.如果有人能准确指出我的机器人出错的地方,那就太好了。

Here is my code:这是我的代码:

function getAfterSpace(str) {
    return str.split(' ')[1]; // get after space
}
client.on("message", msg => {
    if (msg.content.toLowerCase().includes === ";say ") {
        msg.channel.send(`${getAfterSpace(msg.content)}`)
    }
})

Because includes is a method and you are comparing against the method actual method and not an invocation of it.因为includes是一种方法,您正在与方法实际方法进行比较,而不是对它的调用。

It should be msg.content.toLowerCase().includes(";say ") instead.它应该是msg.content.toLowerCase().includes(";say ")

There are many ways to do it, but this is what I would do:有很多方法可以做到这一点,但这是我会做的:

if(message.content.toLowerCase.StartsWith(";say") {
   let result = message.content.split(" "); // creates an array of each word
   result = result.slice(1); // removes first entry (";say");
   result = result.join(" "); // combines each object in the array into a string. each object is separated by a space.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM