0

所以,捎带我之前的问题tick up order number

这个数字会上升,但每隔一段时间它就会在我不做的情况下重置。有没有办法阻止它这样做?

订单号命令:

let baseOrderNumber = 0;
baseOrderNumber++;
        let order = args.join(" ")
        const orderTime = order + Date.now()
        if(order) { client.transferedOrder = order; }
    const orderEmbed = new Discord.MessageEmbed()
    orderIcon = "https://i.imgur.com/Le0Eist.png"
    orderEmbed.setTitle("New Order")
    orderEmbed.setColor("#FF2D00")
    orderEmbed.setThumbnail(orderIcon)
    orderEmbed.addField("Order Number", baseOrderNumber)
    orderEmbed.addField("Order", order)
    orderEmbed.addField("Customer", message.author)
    orderEmbed.addField("Server Invite", invite)
    orderEmbed.addField("Ordered At", message.createdAt)

     bot.channels.cache.get('723838675489914891').send(orderEmbed)    
     let eekowo = fs.writeFileSync('orderAuthors.txt', message.author.tag); 
    }

示例:有人以订单号 #1 下订单;其他人在 5 分钟后下订单,但也有订单号 #1

感谢任何能提供帮助的人

4

2 回答 2

2

您可以在函数之外声明基序号,这样它就不会在每个函数调用中设置为 0。

于 2020-07-04T03:29:46.453 回答
0

baseOrderNumber每次运行命令时,您都在声明一个局部变量:

let baseOrderNumber = 0;

所以它总是初始化为0. 只需将该行在您的范围内上移一级:

目前:

//... other code

function orderNumber {
  let baseOrderNumber = 0;
  baseOrderNumber++;
  let order = args.join(" ")
  //...
}

后:

//... other code

let baseOrderNumber = 0;

function orderNumber {
  baseOrderNumber++;
  let order = args.join(" ")
  //...
}
于 2020-07-04T03:30:08.373 回答