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

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

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

問題描述

我正在開發一個 discord.js 機器人,我想為命令設置冷卻時間.

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

我在 Google 上看到了很多關于如何執行此操作的教程,但所有這些教程都針對所有命令執行此操作(因此,當用戶輸入 !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).

但我想為每個用戶執行此操作(當用戶輸入 !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();

現在在命令事件中添加:

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);
    }

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

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

相關文檔推薦

Using discord.js to detect image and respond(使用 discord.js 檢測圖像并響應)
Check if user ID exists in Discord server(檢查 Discord 服務器中是否存在用戶 ID)
Guild Member Add does not work (discordjs)(公會成員添加不起作用(discordjs))
Creating my first bot using REPLIT but always error Discord.JS(使用 REPLIT 創建我的第一個機器人,但總是錯誤 Discord.JS)
How do I code event/command handlers for my Discord.js bot?(如何為我的 Discord.js 機器人編寫事件/命令處理程序?)
How to find a User ID from a Username in Discord.js?(如何從 Discord.js 中的用戶名中查找用戶 ID?)
主站蜘蛛池模板: 一区二区视频 | 欧美日韩最新 | 久久伊人一区二区 | 97色在线观看免费视频 | 亚洲日本一区二区 | 亚洲品质自拍视频网站 | 国精品一区二区 | 久久综合国产 | 国产一区二 | 国产欧美在线视频 | 中文字幕成人在线 | 91伊人| 精品电影| 欧美在线综合 | 国产人成精品一区二区三 | 麻豆精品国产91久久久久久 | 亚洲一区二区视频在线观看 | 欧美一区二区三区精品免费 | 亚洲欧美在线一区 | 国产亚洲精品综合一区 | 中文字幕亚洲无线 | 婷婷毛片 | 翔田千里一区二区 | 精品国产欧美一区二区三区成人 | 久久久久久久久久久久一区二区 | 亚洲国产精品福利 | 欧美一区二区三区免费电影 | 国产人成在线观看 | 亚洲精品视频免费观看 | 少妇午夜一级艳片欧美精品 | 免费观看羞羞视频网站 | 久久成人在线视频 | 福利视频一区 | 一级片成人 | 国产情侣在线看 | 99精品视频在线 | 国产电影一区二区在线观看 | 日本亚洲一区 | 97色免费视频 | 亚洲福利 | 91精品国产综合久久婷婷香蕉 |