代码-
const Discord = require("discord.js")
const db = require('quick.db')
var today = new Date();
var date = today.getFullYear()+""+(today.getMonth()+1)+today.getDate()+""+ today.getHours()+""+ today.getMinutes()+"" + today.getSeconds()+"" + today.getMilliseconds();
exports.run = async (client, message, args) => {
db.set(`ticket_${message.author.id}`, date);
let yes = await db.fetch( `ticket_${message.author.id}`, date) || 'error'
message.channel.send(`${yes}`)
每次运行命令的时间都不会更新,但是如果我将其放入函数中,它将可以。如何将这段代码转换为函数?
答案 0 :(得分:0)
您的date
变量位于导出的run
函数外部,只需将其移至run
函数内部,即可在调用时对其进行“重新计算”。
const Discord = require("discord.js")
const db = require('quick.db')
exports.run = async (client, message, args) => {
var today = new Date();
var date = today.getFullYear()+""+(today.getMonth()+1)+today.getDate()+""+today.getHours()+""+ today.getMinutes()+"" + today.getSeconds()+"" + today.getMilliseconds();
db.set(`ticket_${message.author.id}`, date);
let yes = await db.fetch( `ticket_${message.author.id}`, date) || 'error'
message.channel.send(`${yes}`)