使用Collector代码制作机器人,如何添加setTimeOut?

时间:2020-08-26 07:49:08

标签: javascript bots discord.js

如何setTimeout在收集邮件后60秒内使用此功能?

这是我的代码:

let setHunt = new Set()
client.on('message', rmsg => {
  var sw = rmsg.content.toLowerCase();
  if (sw == ('rpg hunt') || sw == ('rpg hunt hardmode') || sw === ('rpg hunt h')) {
    if (setHunt.has(rmsg.author.id)) {
      return;
    }
    const filter = m => {
      m.embeds[0] !== undefined && m.embeds[0].description === '**Cooldown**' && m.author.id === '555955826880413696'
    };
    const collector = rmsg.channel.createMessageCollector(filter, {
      time: 1000,
      max: 1
    });
    collector.on('end', m => {})
  }
})

1 个答案:

答案 0 :(得分:0)

您应该阅读如何更好地使用setTimeout函数here

以下是在收藏家中使用它的方法:

let setHunt = new Set();
client.on('message', (rmsg) => {
 var sw = rmsg.content.toLowerCase();
 if (sw == 'rpg hunt' || sw == 'rpg hunt hardmode' || sw === 'rpg hunt h') {
  if (setHunt.has(rmsg.author.id)) {
   return;
  }
  const filter = (m) => {
   m.embeds[0] !== undefined &&
    m.embeds[0].description === '**Cooldown**' &&
    m.author.id === '555955826880413696';
  };
  const collector = rmsg.channel.createMessageCollector(filter, {
   time: 1000,
   max: 1,
  });
  collector.on('end', (m) => {
   setTimeout(() => {

    // your code goes here...

   }, 60000); // 60 seconds in ms
  });
 }
});