diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs index 6fb3ef781..f11db0f13 100644 --- a/src/NadekoBot/Bot.cs +++ b/src/NadekoBot/Bot.cs @@ -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); diff --git a/src/NadekoBot/Common/Creds.cs b/src/NadekoBot/Common/Creds.cs index 6810145ca..5b0243995 100644 --- a/src/NadekoBot/Common/Creds.cs +++ b/src/NadekoBot/Common/Creds.cs @@ -14,12 +14,15 @@ public sealed class Creds : IBotCredentials [Comment(@"List of Ids of the users who have bot owner permissions **DO NOT ADD PEOPLE YOU DON'T TRUST**")] public ICollection OwnerIds { get; set; } + + [Comment("Keep this on 'true' unless you're sure your bot shouldn't use privileged intents or you're waiting to be accepted")] + public bool UsePrivilegedIntents { get; set; } [Comment(@"The number of shards that the bot will running on. Leave at 1 if you don't know what you're doing.")] public int TotalShards { get; set; } - [Comment( + [Comment( @"Login to https://console.cloud.google.com, create a new project, go to APIs & Services -> Library -> YouTube Data API and enable it. Then, go to APIs and Services -> Credentials and click Create credentials -> API key. Used only for Youtube Data Api (at the moment).")] @@ -96,8 +99,9 @@ Windows default public Creds() { - Version = 3; + Version = 4; Token = string.Empty; + UsePrivilegedIntents = true; OwnerIds = new List(); TotalShards = 1; GoogleApiKey = string.Empty; diff --git a/src/NadekoBot/Common/IBotCredentials.cs b/src/NadekoBot/Common/IBotCredentials.cs index 0fe6cfccc..859226e6d 100644 --- a/src/NadekoBot/Common/IBotCredentials.cs +++ b/src/NadekoBot/Common/IBotCredentials.cs @@ -6,6 +6,7 @@ public interface IBotCredentials string Token { get; } string GoogleApiKey { get; } ICollection OwnerIds { get; } + bool UsePrivilegedIntents { get; } string RapidApiKey { get; } Creds.DbOptions Db { get; } diff --git a/src/NadekoBot/Services/Impl/BotCredsProvider.cs b/src/NadekoBot/Services/Impl/BotCredsProvider.cs index 69bea0125..16bbc5f51 100644 --- a/src/NadekoBot/Services/Impl/BotCredsProvider.cs +++ b/src/NadekoBot/Services/Impl/BotCredsProvider.cs @@ -165,9 +165,9 @@ public sealed class BotCredsProvider : IBotCredsProvider if (File.Exists(CREDS_FILE_NAME)) { var creds = Yaml.Deserializer.Deserialize(File.ReadAllText(CREDS_FILE_NAME)); - if (creds.Version <= 2) + if (creds.Version <= 3) { - creds.Version = 3; + creds.Version = 4; File.WriteAllText(CREDS_FILE_NAME, Yaml.Serializer.Serialize(creds)); } } diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index 98dfd0306..057c8d1a7 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -7,7 +7,7 @@ namespace NadekoBot.Services; public class StatsService : IStatsService, IReadyExecutor, INService, IDisposable { - public const string BOT_VERSION = "4.0.0"; + public const string BOT_VERSION = "4.0.1"; public string Author => "Kwoth#2452"; diff --git a/src/NadekoBot/creds_example.yml b/src/NadekoBot/creds_example.yml index c08a0a91c..f7c1eafe7 100644 --- a/src/NadekoBot/creds_example.yml +++ b/src/NadekoBot/creds_example.yml @@ -1,10 +1,12 @@ # DO NOT CHANGE -version: 3 +version: 4 # Bot token. Do not share with anyone ever -> https://discordapp.com/developers/applications/ token: '' # List of Ids of the users who have bot owner permissions # **DO NOT ADD PEOPLE YOU DON'T TRUST** ownerIds: [] +# Keep this on 'true' unless you're sure your bot shouldn't use privileged intents or you're waiting to be accepted +usePrivilegedIntents: true # The number of shards that the bot will running on. # Leave at 1 if you don't know what you're doing. totalShards: 1