首页 > 解决方案 > 我可以参考上一行中的等式结果来发送额外的文本行吗?

问题描述

我是 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!!

标签: javascriptmathrandomreferencediscord

解决方案


当你拥有变量的力量时,为什么要回顾过去?

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

推荐阅读