From c322c25fb03748f34c324d45bf930692cc8c2942 Mon Sep 17 00:00:00 2001 From: Radoslaw Partyka Date: Fri, 1 Jan 2021 16:54:33 +0100 Subject: [PATCH] awaitAvailability in guild struct --- src/structures/guild.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/structures/guild.ts b/src/structures/guild.ts index bda4762..be7eaf3 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -290,6 +290,24 @@ export class Guild extends Base { resolve(this) }) } + + /** + * Fulfills promise when guild becomes available + * @param delay the delay between checking guild availability + */ + async awaitAvailiable( + delay: number = 1000 + ): Promise { + const promise1 = new Promise((resolve, reject) => { + while(true) { + await new Promise(reso => setTimeout(reso, delay)) + if(!this.unavailable) { + resolve() + break; + } + } + }); + } } export class GuildIntegration extends Base {