From 3196f6009329a4db2b3b1d1ea418953bad2c8149 Mon Sep 17 00:00:00 2001 From: Ske Date: Thu, 18 Mar 2021 11:38:28 +0100 Subject: [PATCH] Fix error on DMing with no permission --- PluralKit.Bot/Commands/ImportExport.cs | 5 +++-- PluralKit.Bot/Commands/Token.cs | 4 ++-- PluralKit.Bot/Handlers/ReactionAdded.cs | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/PluralKit.Bot/Commands/ImportExport.cs b/PluralKit.Bot/Commands/ImportExport.cs index 3d289f7d..a4da57ba 100644 --- a/PluralKit.Bot/Commands/ImportExport.cs +++ b/PluralKit.Bot/Commands/ImportExport.cs @@ -5,6 +5,7 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; +using Myriad.Extensions; using Myriad.Rest.Exceptions; using Myriad.Rest.Types; using Myriad.Rest.Types.Requests; @@ -143,7 +144,7 @@ namespace PluralKit.Bot try { - var dm = await ctx.Rest.CreateDm(ctx.Author.Id); + var dm = await ctx.Cache.GetOrCreateDmChannel(ctx.Rest, ctx.Author.Id); var msg = await ctx.Rest.CreateMessage(dm.Id, new MessageRequest {Content = $"{Emojis.Success} Here you go!"}, @@ -154,7 +155,7 @@ namespace PluralKit.Bot if (ctx.Channel.Type != Channel.ChannelType.Dm) await ctx.Reply($"{Emojis.Success} Check your DMs!"); } - catch (UnauthorizedException) + catch (ForbiddenException) { // If user has DMs closed, tell 'em to open them await ctx.Reply( diff --git a/PluralKit.Bot/Commands/Token.cs b/PluralKit.Bot/Commands/Token.cs index a1888fb6..f861b8fb 100644 --- a/PluralKit.Bot/Commands/Token.cs +++ b/PluralKit.Bot/Commands/Token.cs @@ -40,7 +40,7 @@ namespace PluralKit.Bot if (ctx.Channel.Type != Channel.ChannelType.Dm) await ctx.Reply($"{Emojis.Success} Check your DMs!"); } - catch (UnauthorizedException) + catch (ForbiddenException) { // Can't check for permission errors beforehand, so have to handle here :/ if (ctx.Channel.Type != Channel.ChannelType.Dm) @@ -84,7 +84,7 @@ namespace PluralKit.Bot if (ctx.Channel.Type != Channel.ChannelType.Dm) await ctx.Reply($"{Emojis.Success} Check your DMs!"); } - catch (UnauthorizedException) + catch (ForbiddenException) { // Can't check for permission errors beforehand, so have to handle here :/ if (ctx.Channel.Type != Channel.ChannelType.Dm) diff --git a/PluralKit.Bot/Handlers/ReactionAdded.cs b/PluralKit.Bot/Handlers/ReactionAdded.cs index e14070f0..fcbef124 100644 --- a/PluralKit.Bot/Handlers/ReactionAdded.cs +++ b/PluralKit.Bot/Handlers/ReactionAdded.cs @@ -170,7 +170,7 @@ namespace PluralKit.Bot Embed = await _embeds.CreateMessageInfoEmbed(msg) }); } - catch (UnauthorizedException) { } // No permissions to DM, can't check for this :( + catch (ForbiddenException) { } // No permissions to DM, can't check for this :( await TryRemoveOriginalReaction(evt); } @@ -210,7 +210,7 @@ namespace PluralKit.Bot }); await _rest.CreateMessage(dm.Id, new MessageRequest {Content = $"<@{msg.Message.Sender}>".AsCode()}); } - catch (UnauthorizedException) { } + catch (ForbiddenException) { } } await TryRemoveOriginalReaction(evt);