Fix error on DMing with no permission

This commit is contained in:
Ske 2021-03-18 11:38:28 +01:00
parent 4ee0c13d62
commit 3196f60093
3 changed files with 7 additions and 6 deletions

View File

@ -5,6 +5,7 @@ using System.Net.Http;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Myriad.Extensions;
using Myriad.Rest.Exceptions; using Myriad.Rest.Exceptions;
using Myriad.Rest.Types; using Myriad.Rest.Types;
using Myriad.Rest.Types.Requests; using Myriad.Rest.Types.Requests;
@ -143,7 +144,7 @@ namespace PluralKit.Bot
try 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, var msg = await ctx.Rest.CreateMessage(dm.Id,
new MessageRequest {Content = $"{Emojis.Success} Here you go!"}, new MessageRequest {Content = $"{Emojis.Success} Here you go!"},
@ -154,7 +155,7 @@ namespace PluralKit.Bot
if (ctx.Channel.Type != Channel.ChannelType.Dm) if (ctx.Channel.Type != Channel.ChannelType.Dm)
await ctx.Reply($"{Emojis.Success} Check your DMs!"); await ctx.Reply($"{Emojis.Success} Check your DMs!");
} }
catch (UnauthorizedException) catch (ForbiddenException)
{ {
// If user has DMs closed, tell 'em to open them // If user has DMs closed, tell 'em to open them
await ctx.Reply( await ctx.Reply(

View File

@ -40,7 +40,7 @@ namespace PluralKit.Bot
if (ctx.Channel.Type != Channel.ChannelType.Dm) if (ctx.Channel.Type != Channel.ChannelType.Dm)
await ctx.Reply($"{Emojis.Success} Check your DMs!"); await ctx.Reply($"{Emojis.Success} Check your DMs!");
} }
catch (UnauthorizedException) catch (ForbiddenException)
{ {
// Can't check for permission errors beforehand, so have to handle here :/ // Can't check for permission errors beforehand, so have to handle here :/
if (ctx.Channel.Type != Channel.ChannelType.Dm) if (ctx.Channel.Type != Channel.ChannelType.Dm)
@ -84,7 +84,7 @@ namespace PluralKit.Bot
if (ctx.Channel.Type != Channel.ChannelType.Dm) if (ctx.Channel.Type != Channel.ChannelType.Dm)
await ctx.Reply($"{Emojis.Success} Check your DMs!"); await ctx.Reply($"{Emojis.Success} Check your DMs!");
} }
catch (UnauthorizedException) catch (ForbiddenException)
{ {
// Can't check for permission errors beforehand, so have to handle here :/ // Can't check for permission errors beforehand, so have to handle here :/
if (ctx.Channel.Type != Channel.ChannelType.Dm) if (ctx.Channel.Type != Channel.ChannelType.Dm)

View File

@ -170,7 +170,7 @@ namespace PluralKit.Bot
Embed = await _embeds.CreateMessageInfoEmbed(msg) 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); await TryRemoveOriginalReaction(evt);
} }
@ -210,7 +210,7 @@ namespace PluralKit.Bot
}); });
await _rest.CreateMessage(dm.Id, new MessageRequest {Content = $"<@{msg.Message.Sender}>".AsCode()}); await _rest.CreateMessage(dm.Id, new MessageRequest {Content = $"<@{msg.Message.Sender}>".AsCode()});
} }
catch (UnauthorizedException) { } catch (ForbiddenException) { }
} }
await TryRemoveOriginalReaction(evt); await TryRemoveOriginalReaction(evt);