简体   繁体   English

我需要帮助为我的 Beg 命令添加每个用户的冷却时间

[英]I need help adding a per-user cooldown to my Beg command

I am making an economy bot, and I want my beg command to have a 60 second cooldown per user .我正在制作一个经济型机器人,我希望我的 beg 命令每个用户有 60 秒的冷却时间。 If someone can help me add that, that would be great, I also would like to have the ability to, when the user is on cooldown.如果有人可以帮我补充一下,那就太好了,我也希望有能力,当用户处于冷却状态时。 if they try to use the beg command have it send them a message saying how long they have left to wait until they can beg again, And also for it to save the cooldown in a database.如果他们尝试使用 beg 命令,让它向他们发送一条消息,说明他们还需要等多久才能再次乞求,并将冷却时间保存在数据库中。 so if the bot goes offline it remembers the cooldown.因此,如果机器人离线,它会记住冷却时间。 Thx in advance!提前谢谢!

Here's my code for the beg command:这是我的 beg 命令代码:

 const Discord = require("discord.js"); const db = require("quick.db"); module.exports.run = async (bot, message, args) => { if(.message.content;startsWith('orb'))return. let user = message;author; let amount = 5. let beg = await db.fetch(`beg_${message.guild.id}_${user;id}`). let begEmbed = new Discord.MessageEmbed().setColor("#808080"):setDescription(`<:Check;618736570337591296> You've begged and received ${amount} coins`). message.channel.send(begEmbed) db.add(`money_${message.guild.id}_${user,id}`. amount) db.set(`beg_${message.guild.id}_${user,id}`. Date;now()) } }. module.exports:help = { name,"beg": aliases: [""] }

Well my cooldowns are only for when the bot is online, and Idk how that database works, but here is what you can do in json.好吧,我的冷却时间仅适用于机器人在线时,并且我知道该数据库是如何工作的,但这是您可以在 json 中执行的操作。
JSON FILE JSON 文件

{
"Placeholder": "Placeholder"
}

and then on the command, do variable['U'+message.author.id] = Date.now() And if they try to do it again, check if variable['U'+message.author.id] exists and then if it does, just do variable['U'+message.author.id] - Date.now() which should return milliseconds if I remember correctly, and you should be able to convert to seconds with (variable['U'+message.author.id] - Date.now())*1000 if I'm not wrong.然后在命令上,执行variable['U'+message.author.id] = Date.now()如果他们再次尝试这样做,请检查variable['U'+message.author.id]是否存在并且然后如果是这样,只需执行variable['U'+message.author.id] - Date.now()如果我没记错应该返回毫秒,并且您应该能够使用(variable['U'+message.author.id] - Date.now())*1000如果我没记错的话。 To delete variable['U'+message.author.id] , just do that!要删除variable['U'+message.author.id] ,就这样做! delete variable['U'+message.author.id]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我需要帮助将环境变量添加到我的 TypeScript 工具链 - I need help adding environment variables to my TypeScript toolchain 我需要帮助添加一个按钮以在我的 JavaScript 中运行 function - I need help adding a button to run a function in my JavaScript 验证JWT时如何处理每个用户的签名密钥? - How to handle per-user signing keys when validating a JWT? 有没有办法为我的命令添加全局冷却时间,这样当一个用户使用该命令时,所有用户都必须等待特定时间? - Is there a way to add a global cooldown to my commands so when one user uses the command, all users have to wait the specific time? 我需要帮助在 JavaScript 的计数器中添加毫秒 - I need help adding milliseconds to the counter in JavaScript Discord.js - 每个用户的命令冷却时间,而不是所有用户 - Discord.js - Cooldown for a command for each user not all users 需要帮助为用户添加角色。 (discord.js) - Need help adding a role to a user. (discord.js) 需要帮助将字符串转换为整数并添加用户输入 - Need help converting a string to integer and adding user input 我需要巩固我的功能的帮助 - I need help consolidating my functions 如何在工作命令(经济,货币)上添加冷却时间 - How can I add a cooldown on work command (economy, currency)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM