首页 > 解决方案 > discord.js way to put a limit on what the bot reads

问题描述

When I run the command and my bot takes the code it reads what is In front of it, please help

    let sentence = message.content.split("2");
    sentence.shift();
    sentence = sentence.join(" ");
    

    let input = message.content.split("1");
    input.shift();
    // Made a variable that removes what comes before
    // it but cant figure it out to stop reading what is before
    input = input.join(" ");
    

    (message.channel.send(sentence));
    (message.channel.send(input))

essentially bot does this

*MAE 1test 2no

bot, no test 2no please help

this is my first time making a question on stack overflow so it might be rough. thank you for the help.

标签: javascriptdiscord.js

解决方案


欢迎来到 SO!我不太明白你想做什么。但我会尽力而为,所以如果我有任何问题,请在下方评论。似乎您正在尝试删除命令的第一部分,即前缀,以获取命令本身这就是我的做法。

const prefix = "abc!"
const msgContent = "abc!help"

const command = msgContent.substr(prefix.length)

console.log(command)

如果您想了解介于1and之间的内容2

const startChar = "1"
const endChar = "2"

const messageContent = "blahblah1hello2blahblah"

const command = messageContent.match(/(1)*([a-z])*2/)[0].slice(1, -1)

console.log(command)


推荐阅读