【问题标题】:Chat bot command cooldown聊天机器人命令冷却时间
【发布时间】:2017-07-08 21:52:03
【问题描述】:

所以我正在开发一个使用 discord.js 的 Discord Bot,discord.js 是 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);

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

【问题讨论】:

    标签: javascript node.js discord


    【解决方案1】:

    您可以为“被阻止”的用户使用数组。 每次用户使用 ping 命令时,您将 id 添加到数组并使用 setTimeout(function(){},3000) 再次删除它。

    【讨论】:

      猜你喜欢
      • 2017-09-08
      • 2021-06-17
      • 2019-06-28
      • 2019-12-29
      • 2017-11-21
      • 2018-09-18
      • 2021-03-11
      • 2019-03-11
      • 1970-01-01
      相关资源
      最近更新 更多