基本的一消息骰子滚轮? [英] Basic one-message dice roller?

查看:100
本文介绍了基本的一消息骰子滚轮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在此处,并且我想添加一个简单的骰子滚动功能,该功能不会占用多条消息,因此不会向我所在的服务器发送垃圾邮件。

This is the same discord bot I've asked about in the last question I posted here, and I want to add a simple dice rolling function that doesn't take up multiple messages so I don't spam the server I'm in.

到目前为止,我有骰子滚子本身的准系统代码在这里工作:

So far, I have the barebones code for the dice roller itself working here:

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);
}

到目前为止,它只是吐出一个数字

And as of right now it just spits out the number like

96

这...非常不适合这个机器人我赋予了很多个性。我想要的是在它喷出的数字前后都有文字,例如。

which is... very out of character for this bot I've given so much personality. What I want is for there to be text before and after the number it spits out, like so.

您得到了……96!

如果我在代码中添加了类似的内容,它会产生部分相同的效果,它只会很尴尬地发送两条不同的消息,

If I put something like this into the code it has partially the same effect, it just sends really awkwardly and in two different messages, which isn't what I want.

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);
}

感谢您对任何帮助进行故障排除的帮助!谢谢!

Any help troubleshooting is appreciated! Thanks!

推荐答案

我认为您本质上是在问如何将字符串连接在一起。这是通过加号运算符完成的。如果任何操作数是字符串,它将所有变量视为字符串:

I think you are essentially asking how to concatenate strings together. That is done with the plus sign operator. If any of the operands are strings, it treats all the variables as strings:

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!"
}

或者,您可以像这样使用模板参数(那些是反引号,而不是引号):

Alternatively, you can use template params like so (those are backticks, not quotes):

message.channel.send(`You got... ${response}!`);

这篇关于基本的一消息骰子滚轮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆