javascript - 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.
解决方案
欢迎来到 SO!我不太明白你想做什么。但我会尽力而为,所以如果我有任何问题,请在下方评论。似乎您正在尝试删除命令的第一部分,即前缀,以获取命令本身。这就是我的做法。
const prefix = "abc!"
const msgContent = "abc!help"
const command = msgContent.substr(prefix.length)
console.log(command)
如果您想了解介于1
and之间的内容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)
推荐阅读
- xamarin - 如何更改 Android 的 Xamarin.Forms Frame 默认选定边框?
- r - R 新手,尽管安装了 lubridate,但无法使用 floor_date 命令
- laravel - 在 Laravel 8 中创建包含作业、事件、侦听器、队列的结构
- jdbc - 限制jdbc连接池固定数量
- php - SQL - 创建与另一个值匹配的值数组
- format - EPPlus - 将单元格格式复制到新单元格
- amazon-web-services - 将资产从一个 S3 存储桶定期自动同步到单独账户中的另一个存储桶
- php - 执行命令时 laravel 出现问题:php artisan migrate
- java - 有没有办法在 bazel 构建中调用 java 代码(类似于自定义 maven 插件)?
- linux - 使用 shell 更改文件内变量中设置的目录路径