【发布时间】:2019-03-24 23:53:10
【问题描述】:
所以我有一个同步函数 (client.functionOne),它创建了一个 Discord.js 消息收集器,它删除发送到通道的消息。该函数还调用了一个异步函数,该函数创建了一个setTimeout 循环。
问题是,由于某种原因,每当client.functionTwo 中的代码运行时,“收集”功能就会被阻止,并且它的运行速度不如不运行时的速度。
我不确定它为什么这样做。有人可以帮忙吗?提前致谢。
client.functionTwo = async (channel) => {
let timeout;
const interval = async () => {
// Logic here with several awaits
// Schedule a new timeout
timeout = setTimeout(interval, 2000);
}
interval();
}
client.functionOne = (channel) => {
setTimeout(() => {
const collector = channel.createMessageCollector(() => true, { time: 150000 });
client.functionTwo(channel);
collector.on("collect", (message) => {
if (message.author.bot) return;
message.delete();
});
}, 1000);
}
【问题讨论】:
-
我不会调用任何创建
setTimeout或调用functionTwo“同步”的函数。
标签: javascript asynchronous async-await discord.js