Bots receive GUILD_CREATE for every existing guild on connect

(#837) Bug Fixed api

Observed behaviour

I'm developing my own bot and when I use Events.GuildCreate from @fluxerjs/core, the bot lists all guilds it's in every time I start the bot.

Reproduction steps

register the event by calling it on the client, then execute it. here is my event file
import { Events } from "@fluxerjs/core";

const guildCreateEvent = {
    event: Events.GuildCreate,
    execute: async (client: any, guild: any) => {
        console.log(`Joined guild: ${guild.name} (ID: ${guild.id})`);
    },
};

export default guildCreateEvent;
Here is a back-to-back test run
 *  Executing task: npm run start 

npm notice run fluxer-getting-started-bot@1.0.0 start
npm notice run tsx src/index.ts
Getting Started Bot is connected to Fluxer.
Command prefix: !
Joined guild: Getting Started (ID: 1548890981661671424)

 *  The terminal process 'npm run start'" terminated with exit code: 512. 
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: npm run start 

npm notice run fluxer-getting-started-bot@1.0.0 start
npm notice run tsx src/index.ts
Getting Started Bot is connected to Fluxer.
Command prefix: !
Joined guild: Getting Started (ID: 1548890981661671424)

Build information

"@fluxerjs/core": "^3.0.0"

Platform

API

10 comments

Sign in with Fluxer to comment and vote.
Comment by @GlitchApotamus
RexSystem 1 vote originally by @GlitchApotamus on GitHub OP
Actually discord has a different behavior. That exact event in discord only fires when the bot actually joins a new guild, not every time the bot starts up. I host my own discord bots, and am well aware how they handle it. I was going to see if I could add a fix myself, but the fluxer repo was a bit confusing to me.
Comment by Tarek
TarekMod 1 vote originally by @Taarek on GitHub
What discord bot library do you use for your Discord bots?
Comment by Hampus
HampusStaff 1 vote originally by @hampus-fluxer on GitHub
Discord actually does send GUILD_CREATE lazily after connecting for bots, this is documented clearly in their own docs and I can recreate that behaviour with a raw WebSocket connection currently. If you previously relied on behaviour where it does not, that must be something your bot library has masked for you on Discord previously, which is possible to do if it doesn't let you use the bot until all guilds have arrived asynchronously after READY, so this requires no changes to Fluxer source code, but either changes to the library you use, or your expectations of said library.
Comment by @GlitchApotamus
RexSystem 1 vote originally by @GlitchApotamus on GitHub OP
I've always used Discord.JS and Discord.py I never knew they masked the guilds, even when I made my own handlers, I never saw currently connected guilds.
Comment by Hampus
HampusStaff 1 vote originally by @hampus-fluxer on GitHub
So it turns out that there is one thing that Fluxer can do differently to make implementing this behaviour that other libraries have easier. Currently, it would require them doing a REST call to list the bot's guilds to know which ones to await. Fluxer matches Discord's behaviour with asynchronously sending GUILD_CREATEs, but bot libraries mask this due to the fact that Discord gives them all guild IDs for free in READY in guilds as unavailable guilds. Fluxer currently returns an empty array for bots. This is easily fixed, however, and will make doing the same thing here much easier for bot libraries on Fluxer, aligning perfectly with Discord.
Comment by @GlitchApotamus
RexSystem 1 vote originally by @GlitchApotamus on GitHub OP
That would be outstanding! I'm actually writing my own library as we chat.
Comment by @GlitchApotamus
RexSystem 1 vote originally by @GlitchApotamus on GitHub OP
If you open up a pr to make this happen, please tag me! I would love to input on it as well.