这是我在这里发布的最后一个问题中问的同样的Discord bot,我想添加一个简单的骰子滚动功能,该功能不接收多个消息,所以我不要垃圾邮件我所在的服务器。
到目前为止,我的骰子辊本身的准则代码在这里工作:
if (message.content.toLowerCase().includes("rei!d100")) {
var response = [Math.floor(Math.random() * ((100 - 1) + 1) + 1)];
message.channel.send(response).then().catch(console.error);
}
现在,它只是吐出数字
96
这是...这个机器人非常不合时宜。我想要的是要在数字吐出之前和之后都有文字,就像这样。
You got... 96!
如果我将类似的内容放入代码中,它具有相同的效果,它只是尴尬地发送,而在两个不同的消息中,这不是我想要的。
if (message.content.toLowerCase().includes("rei!d100")) {
message.channel.send("You got...");
var response = [Math.floor(Math.random() * ((100 - 1) + 1) + 1)];
message.channel.send(response).then().catch(console.error);
}
任何帮助故障排除将不胜感激!谢谢!
我认为您本质上是在询问如何连接串在一起。这是使用加号运算符完成的。如果任何操作数是字符串,它将所有变量都视为字符串:
if (message.content.toLowerCase().includes("rei!d100")) {
var response = [Math.floor(Math.random() * ((100 - 1) + 1) + 1)];
message.channel.send("You got... " + response + "!").then().catch(console.error); // "You got... 96!"
}
另外,您可以使用模板参数(这些是背部,而不是引号(:
message.channel.send(`You got... ${response}!`);