我可以参考上一行中的等式结果来发送额外的文本行吗?
Can I reference the result of the equation in the previous line to send an additional line of text?
我是 JS 的超级新手,目前正在开发一个 discord 机器人。
我正在寻找一种方法来引用正在生成的上述结果(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!
备用当前结果:@用户掷出 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!');
}
}
我是 JS 的超级新手,目前正在开发一个 discord 机器人。 我正在寻找一种方法来引用正在生成的上述结果(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!
备用当前结果:@用户掷出 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!');
}
}