SinisterRectus / Discordia

Discord API library written in Lua for the Luvit runtime environment
MIT License
688 stars 144 forks source link

Fix for certain events not triggering (in v8?) #371

Closed Lort533 closed 1 year ago

Lort533 commented 1 year ago

Fixes e.g. GUILD_MEMBER_ADD event not triggering at all (Discord won't send it in the first place). Intent code generated thanks to https://discord-intents-calculator.vercel.app/. It would be best to verify if that intent code is actually the good one before pulling this request, because I only tested it on one event, and it worked.

Idea for fixing this issue came from here: https://stackoverflow.com/a/65640810

Bilal2453 commented 1 year ago

From https://github.com/SinisterRectus/Discordia/discussions/369:

Privileged intents include: guildMembers, guildPresences, and messageContent. If you do not want to use privileged intents, no user code changes are required. [...] to use privileged intents in your bot, you must programmatically enable them in your bot code. To do this, you may use the enableIntents, enableAllIntents, or setIntents client methods after initilizing your Client instance, but before calling run.

So first of all, GUILD_MEMBER_ADD requires the Member privileged intent, hence Discordia does not enable it by default. It instead asks the user to do so with one of the provided methods (or in the client options).

For example you do:

local client = discordia.Client {
    gatewayIntents = 3276799,
}

Since intents are now required and privileged intents are disabled by default, some side-effects may be seen. If you do not enable certain intents, your bot will simply never receive the events that are governed by those intents.

Hence you don't receive the event at all, this also includes:

To summarize, this behavior is intentional and should not be changed, it was done to prevent bots that do not have the privileged intents enabled from breaking (the event in question is memberJoin); and instead the user needs to explicitly enable that in code after enabling it in the developer page. I really advise to read https://github.com/SinisterRectus/Discordia/discussions/369 as you are transitioning into API v8 as it contains important clues.

Good luck

Lort533 commented 1 year ago

Okay, I haven't seen that announcement, I'm sorry for making this pull request.

Thank you.