久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Discord.js - 每個用戶的命令冷卻時間,而不是所有

Discord.js - Cooldown for a command for each user not all users(Discord.js - 每個用戶的命令冷卻時間,而不是所有用戶)
本文介紹了Discord.js - 每個用戶的命令冷卻時間,而不是所有用戶的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在開發(fā)一個 discord.js 機(jī)器人,我想為命令設(shè)置冷卻時間.

I am developing a discord.js bot and I want to make a cooldown for a command.

我在 Google 上看到了很多關(guān)于如何執(zhí)行此操作的教程,但所有這些教程都針對所有命令執(zhí)行此操作(因此,當(dāng)用戶輸入 !mycmd 時,所有用戶都必須等待 X 分鐘/秒才能輸入再次).

I saw a lot of tutorials on how to do it on Google, but all those tutorials do it for all the commands (so when a user type !mycmd all the users have to wait X minutes/seconds until it can be typed again).

但我想為每個用戶執(zhí)行此操作(當(dāng)用戶輸入 !mycmd 時,只有該用戶必須等待 X 分鐘/秒,直到用戶可以再次輸入).

But I want to do it for each user (when a user type !mycmd , ONLY this user have to wait X minutes/seconds until THE USER can type it again).

有可能嗎?

謝謝!

推薦答案

是的,這很容易而且可能.

Yes it is easy and possible.

在你的 JS 文件的頂部添加這個:

Add this at the top of your JS file:

// First, this must be at the top level of your code, **NOT** in any event!
const talkedRecently = new Set();

現(xiàn)在在命令事件中添加:

Now in the command event add this:

    if (talkedRecently.has(msg.author.id)) {
            msg.channel.send("Wait 1 minute before getting typing this again. - " + msg.author);
    } else {

           // the user can type the command ... your command code goes here :)

        // Adds the user to the set so that they can't talk for a minute
        talkedRecently.add(msg.author.id);
        setTimeout(() => {
          // Removes the user from the set after a minute
          talkedRecently.delete(msg.author.id);
        }, 60000);
    }

這篇關(guān)于Discord.js - 每個用戶的命令冷卻時間,而不是所有用戶的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Using discord.js to detect image and respond(使用 discord.js 檢測圖像并響應(yīng))
Check if user ID exists in Discord server(檢查 Discord 服務(wù)器中是否存在用戶 ID)
Guild Member Add does not work (discordjs)(公會成員添加不起作用(discordjs))
Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 創(chuàng)建我的第一個機(jī)器人,但總是錯誤 Discord.JS)
How do I code event/command handlers for my Discord.js bot?(如何為我的 Discord.js 機(jī)器人編寫事件/命令處理程序?)
How to find a User ID from a Username in Discord.js?(如何從 Discord.js 中的用戶名中查找用戶 ID?)
主站蜘蛛池模板: 黄色免费在线网址 | 国产精品成人一区二区三区夜夜夜 | 啪啪av | 国产高清在线精品 | 久久免费精品视频 | 日韩欧美中文字幕在线观看 | 亚洲国产精品视频一区 | 国产中文原创 | 国产高清视频 | 久久精品一区二区视频 | 久久久精| 久草.com| 亚洲网在线 | 欧美一级欧美三级在线观看 | 欧美精品一级 | 日韩欧美精品在线播放 | 国产精品福利在线观看 | 在线观看欧美一区 | 国产一区二区三区免费观看在线 | 亚洲视频一区在线观看 | 亚洲第一在线视频 | 国产精品国产三级国产aⅴ原创 | 精品视频久久久久久 | 自拍视频国产 | 久久精品国产一区二区电影 | 中文在线一区 | 久久久久免费精品国产小说色大师 | 亚洲成人免费观看 | 拍真实国产伦偷精品 | 91国在线高清视频 | 欧美精品久久久久久 | 在线综合视频 | 国产精品毛片av一区 | 高清久久久 | 久久看片| 精品影院| 欧美三级久久久 | 中文字幕在线不卡 | 视频一区二区三区四区五区 | 天天搞天天搞 | 男女深夜网站 |