2017-02-19 190 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)再次删除它。