From ebf8a403695f10a947430aa59e90fe99d708c2bd Mon Sep 17 00:00:00 2001 From: asleepyskye Date: Tue, 9 Sep 2025 11:32:13 -0400 Subject: [PATCH] fix(bot): fix utility admin command --- PluralKit.Bot/Commands/Admin.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/PluralKit.Bot/Commands/Admin.cs b/PluralKit.Bot/Commands/Admin.cs index da859616..44171345 100644 --- a/PluralKit.Bot/Commands/Admin.cs +++ b/PluralKit.Bot/Commands/Admin.cs @@ -10,6 +10,7 @@ using Myriad.Cache; using Myriad.Rest; using Myriad.Types; using Myriad.Rest.Types.Requests; +using Myriad.Rest.Exceptions; using PluralKit.Core; @@ -20,12 +21,14 @@ public class Admin private readonly BotConfig _botConfig; private readonly DiscordApiClient _rest; private readonly IDiscordCache _cache; + private readonly PrivateChannelService _dmCache; - public Admin(BotConfig botConfig, DiscordApiClient rest, IDiscordCache cache) + public Admin(BotConfig botConfig, DiscordApiClient rest, IDiscordCache cache, PrivateChannelService dmCache) { _botConfig = botConfig; _rest = rest; _cache = cache; + _dmCache = dmCache; } private Task<(ulong Id, User? User)[]> GetUsers(IEnumerable ids) @@ -513,15 +516,16 @@ public class Admin try { - var dm = await _rest.CreateDm(account.Id); - var msg = await ctx.Rest.CreateMessage(dm.Id, + var dm = await _dmCache.GetOrCreateDmChannel(account.Id); + var msg = await ctx.Rest.CreateMessage(dm, new MessageRequest { Content = messageContent } ); } - catch (Exception) + catch (ForbiddenException) { await ctx.Reply( $"{Emojis.Error} Error while sending DM."); + return; } await ctx.Reply($"{Emojis.Success} Successfully sent message.");