2017-02-19 189 views
0

因此,我正在使用Discord.js(一個用於Discord API的node.js包裝器)的Discord Bot。基本上,代碼是這樣的:聊天機器人命令cooldown

/* 
    A ping pong bot, whenever you send "ping", it replies "pong". 
*/ 

// import the discord.js module 
const Discord = require('discord.js'); 

// create an instance of a Discord Client, and call it bot 
const bot = new Discord.Client(); 

// the token of your bot - https://discordapp.com/developers/applications/me 
const token = 'your bot token here'; 

// create an event listener for messages 
bot.on('message', message => { 
    // if the message is "ping", 
    if (message.content === 'ping') { 
    // send "pong" to the same channel. 
    message.channel.sendMessage('pong'); 
    } 
}); 
bot.login(token); 

但我的問題是,我怎樣才能讓這個用戶只能使用與3秒的冷卻時間的「ping」命令。要做到這一點,你需要用戶ID,如果你想知道的話,那就是message.author.id。提前致謝。

回答

0

您可以爲「封鎖」的用戶使用數組。 每次用戶使用ping命令將該ID添加到陣列並使用setTimeout(function(){},3000)再次刪除它。