如何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 => {})
}
})
答案 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
});
}
});