首页 文章

聊天机器人命令冷却时间

提问于
浏览
0

所以我正在开发一个使用discord.js的Discord Bot,它是Discord API的node.js包装器 . 基本上代码的工作方式如下:

/*
  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);

但我的问题是,我怎样才能使用户只能使用“ping”命令,冷却时间为3秒 . 要做到这一点,你需要用户ID,如果你想知道那将是message.author.id . 提前致谢 .

1 回答

  • 0

    您可以为"blocked"用户使用数组 . 每次用户使用ping命令时,都会将id添加到数组中,并使用 setTimeout(function(){},3000) 再次删除它 .

相关问题