From 1b89cfd516c2e0ac802f4bf03322714f66219d9d Mon Sep 17 00:00:00 2001 From: Sakuhl <2012collector@gmail.com> Date: Tue, 7 Aug 2018 23:52:03 +0200 Subject: [PATCH] Properly report total guild count --- src/commands/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 9009b7d..078839a 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -104,7 +104,7 @@ pub fn wc_territory(command: &str, msg: &Message) -> Result<(), Error> { } pub fn wc_info(msg: &Message) -> Result<(), Error> { - let guilds = serenity::http::get_current_user()?.guilds()?.len(); + let guilds = get_guild_count()?; msg.channel_id.say(format!("Developer: Wurst#1783 Forum thread: https://forums.wynncraft.com/threads/discord-bot.212142/ Discord: https://discord.gg/GbN7HeG @@ -114,6 +114,16 @@ Servers: {}", env!("CARGO_PKG_VERSION"), guilds))?; Ok(()) } +fn get_guild_count() -> Result { + let mut guilds = 0; + let mut new_guilds = serenity::http::get_guilds(&serenity::http::GuildPagination::After(GuildId(0)), 100)?; + while !new_guilds.is_empty() { + guilds += new_guilds.len(); + new_guilds = serenity::http::get_guilds(&serenity::http::GuildPagination::After(new_guilds.last().unwrap().id), 100)?; + } + Ok(guilds) +} + pub fn wc_help(msg: &Message) -> Result<(), Error> { if let Err(_) = msg.author.dm(|f| f.content("Command overview: (prefix is wc!)