基本的单信息掷骰子?
Basic one-message dice roller?
这就是我在上一个问题 here 中询问过的同一个 discord 机器人,我想添加一个简单的骰子滚动功能,它不会占用多条消息,所以我不不要向我所在的服务器发送垃圾邮件。
到目前为止,我有骰子滚筒本身的准系统代码在这里工作:
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}!`);
这就是我在上一个问题 here 中询问过的同一个 discord 机器人,我想添加一个简单的骰子滚动功能,它不会占用多条消息,所以我不不要向我所在的服务器发送垃圾邮件。
到目前为止,我有骰子滚筒本身的准系统代码在这里工作:
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}!`);