From 943da83993d1447d7b1d189862752f14e78c4d72 Mon Sep 17 00:00:00 2001 From: nolan Date: Tue, 24 Aug 2021 16:01:34 -0700 Subject: [PATCH] Add activity --- src/structure/DiscordClient.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/structure/DiscordClient.js b/src/structure/DiscordClient.js index 096efe0..ae3948f 100644 --- a/src/structure/DiscordClient.js +++ b/src/structure/DiscordClient.js @@ -27,6 +27,14 @@ class DiscordClient extends Client { this._options = options; this._built = false; + this.once('ready', () => { + this._setActivity(); + + setInterval(() => { + this._setActivity(); + }, 1800000); // I think this is 30 minutes. I could be wrong. + }); + } async build() { @@ -54,6 +62,27 @@ class DiscordClient extends Client { } + async _setActivity() { + const activities = { + 0: async () => { + const guildCount = (await this.shard.broadcastEval('this.guilds.cache.size')).reduce((p, v) => p+v, 0); + this.user.setActivity(`${guildCount} servers`, { type: 'WATCHING' }); + }, + 1: async () => { + const userCount = (await this.shard.broadcastEval('this.users.cache.size')).reduce((p, v) => p+v, 0); + this.user.setActivity(`to ${userCount} users`, { type: 'LISTENING' }); + }, + 2: async () => { + this.user.setActivity("to /help", { type: 'LISTENING' }); + } + }; + + await activities[this._activity](); + if(this._activity === Math.max(...Object.keys(activities))) this._activity = 0; + else this._activity++; + + } + get singleton() { return Boolean(this.shard.ids[0] === 0); }