javascript - 我可以参考上一行中的等式结果来发送额外的文本行吗?
问题描述
我是 JS 的超级新手,目前正在开发一个不和谐的机器人。我正在寻找一种方法来引用正在生成的上述结果(从 1 到 20 的数字),如果结果恰好是 20,则让命令发送附加消息。谁能帮我解决这个问题,任何提示将不胜感激?谢谢。下面的例子。
当前代码:
module.exports = {
name: 'roll',
description: "this is a roll command!",
execute(message, args){
message.channel.send(`${message.author} rolled a **D20** <:d20:790654162600853535> and got***${Math.floor(Math.random() * 20) + 1}*** !`);
}
}
当前结果:@User 掷出 D20 并得到 20!
替代当前结果:@User 掷出 D20 并得到 5!
想要的结果:@User 掷出 D20 并得到 20!!
@User rolled a Critical!
替代通缉结果:@User 掷出 D20 并得到 5!!
解决方案
当你拥有变量的力量时,为什么要回顾过去?
module.exports = {
name: 'roll',
description: "this is a roll command!",
execute(message, args){
let roll = Math.floor(Math.random() * 20) + 1
message.channel.send(`${message.author} rolled a **D20** <:d20:790654162600853535> and got***${roll}*** !`);
if (roll === 20) message.channel.send('@User rolled a Critical!');
}
}
推荐阅读
- xamarin.forms - Xamarin Forms - 内容页面中的 webkit
- c - 如何用C语言写日记?
- python - TypeError:导入 sklearn 时需要一个整数(获取类型字节)
- c++ - 如何在 MacOS (OS X) 上将 GNU make 4.3 设为默认
- android - 如何实现具有弯曲角的可绘制形状
- angular - 为什么 Angular 2 从链接中删除 index.html 并重定向到我的路由链接?
- python - 需要高级 Python 书籍推荐
- javascript - Recaptcha 缺少元素“data-sitekey”,因此无法使用任何验证码服务 api
- python - Tkinter, how to get/return value by clicking a button in for-loop?
- qt - 未找到具有已注册类型的 QML 模块