所以我做了一种简单的 DIY 之类的东西。 (大声笑,实际上我在看到问题时做了这个,花了大约 5 分钟。)
它允许您使用运算符|(BackSpace 下方的那个)解析消息。
我尝试在eval 命令中使用它,所以我确信它有效。
代码是:
// Creating array variables so it doesn't return undefined when we try to `.concat()` it.
let sentences = [];
let temp = [];
// Loops every args
for(l=0;l<args.length;l++) {
// Adding the args as an array to the `temp` variable.
temp = temp.concat(argss[l])
// If we meet `|` which is a sentence separator.
if (args[l] === "|") {
// Join the `temp` array, making it a sentence while removing the `|` operator.
sentences = sentences.concat(temp.join(' ').slice(0, -2));
// Resetting `temp` to reset the saved sentence and start a new one.
temp = [];
}
}
使用.join(' ') 将不起作用,因为它从数组中返回一个字符串,因此不能使用连接\n。
上述方法可能更有效。他们使用如下命令:
// Say prefix is `.` and the command is `embed`
.embed <header> | <content> | <title1> | <sentence1> | <title2> | <sentence2> |
你将分别得到sentences[0]、sentences[1]、sentences[2]、sentences[3]、sentences[4]、sentences[5]。然后,您可以将其添加到您的嵌入中。
这也将允许多字符串输入,而不是单个参数。不要忘记最后的|,因为没有它,它会忽略整个最后一句。
const sayEmbed = new Discord.MessageEmbed()
.setColor('#4d4d4d')
.setTitle(sentences[0]) // <header>
.setDescription(sentences[1]) // <content>
.addField(sentences[2], sentences[3]) // <title1> <sentence1>
.addField(sentences[4], sentences[5]) // <title2> <sentence2>
// The more you add, the more it'll allow, you'll have to set it yourself.
TL;DR:更简单的答案:
sentences = args.join(" ").split(" | ");
对不起,我经常做事很辛苦。