[英]How do I turn this javascript code into a function?
代码 -
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}`)
每次运行命令时时间都不会更新,但是如果我将其放入 function 中,它会。 如何将这段代码变成 function?
您的date
变量在导出的run
function 之外,只需将其移动到run
function 内部即可使其在调用时“重新计算”。
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}`)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.