From cad5b71f14a28d351048dd0596cee5d5cbd7f415 Mon Sep 17 00:00:00 2001 From: Ske Date: Sat, 2 May 2020 15:33:05 +0200 Subject: [PATCH] Fix system lookup errors where user ID doesn't exist --- PluralKit.Bot/Commands/CommandTree.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/PluralKit.Bot/Commands/CommandTree.cs b/PluralKit.Bot/Commands/CommandTree.cs index 900811aa..a20a0505 100644 --- a/PluralKit.Bot/Commands/CommandTree.cs +++ b/PluralKit.Bot/Commands/CommandTree.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading.Tasks; using DSharpPlus; +using DSharpPlus.Exceptions; using PluralKit.Core; @@ -346,12 +347,16 @@ namespace PluralKit.Bot { // Try to resolve the user ID to find the associated account, // so we can print their username. - var user = await ctx.Rest.GetUserAsync(id); - - // Print descriptive errors based on whether we found the user or not. - if (user == null) + try + { + var user = await ctx.Rest.GetUserAsync(id); + return $"Account **{user.Username}#{user.Discriminator}** does not have a system registered."; + } + catch (NotFoundException) + { + // User not found, just return ID return $"Account with ID `{id}` not found."; - return $"Account **{user.Username}#{user.Discriminator}** does not have a system registered."; + } } return $"System with ID `{input}` not found.";