Added usePrivilegedIntents to creds.yml as an option for users who don't have them enabled

Added an explanation on how to enable intents if the bot doesn't have them and fails to login
This commit is contained in:
Kwoth
2022-03-03 02:31:32 +01:00
parent 01cc6e52d5
commit 03367c5ec4
6 changed files with 44 additions and 9 deletions

View File

@@ -52,7 +52,7 @@ public sealed class Bot
#else
50;
#endif
Client = new(new()
{
MessageCacheSize = messageCacheSize,
@@ -63,7 +63,9 @@ public sealed class Bot
AlwaysDownloadUsers = false,
AlwaysResolveStickers = false,
AlwaysDownloadDefaultStickers = false,
GatewayIntents = GatewayIntents.All,
GatewayIntents = _creds.UsePrivilegedIntents
? GatewayIntents.All
: GatewayIntents.AllUnprivileged,
LogGatewayIntentWarnings = false,
});
@@ -337,7 +339,33 @@ public sealed class Bot
private Task Client_Log(LogMessage arg)
{
if (arg.Exception is not null)
if (arg.Message?.Contains("unknown dispatch", StringComparison.InvariantCultureIgnoreCase) ?? false)
return Task.CompletedTask;
if (arg.Exception is WebSocketClosedException { CloseCode: 4014 })
{
Log.Warning(@"
Login failed.
*** Please enable privileged intents ***
Certain Nadeko features require Discord's privileged gateway intents.
These include greeting and goodbye messages, as well as creating the Owner message channels for DM forwarding.
How to enable privileged intents:
1. Head over to the Discord Developer Portal https://discord.com/developers/applications/
2. Select your Application.
3. Click on `Bot` in the left side navigation panel, and scroll down to the intents section.
4. Enable both intents.
5. Restart your bot.
Read this only if your bot is in 100 or more servers:
You'll need to apply to use the intents with Discord, but for small selfhosts, all that is required is enabling the intents in the developer portal.
Yes, this is a new thing from Discord, as of October 2020. No, there's nothing we can do about it. Yes, we're aware it worked before.
While waiting for your bot to be accepted, you can change the 'usePrivilegedIntents' inside your creds.yml to 'false', although this will break many of the nadeko's features");
}
else if (arg.Exception is not null)
Log.Warning(arg.Exception, "{ErrorSource} | {ErrorMessage}", arg.Source, arg.Message);
else
Log.Warning("{ErrorSource} | {ErrorMessage}", arg.Source, arg.Message);