Skip to content

Commit

Permalink
Changed GetUser() to throw UserNotFoundException when the bot is unab…
Browse files Browse the repository at this point in the history
…le to get the user
  • Loading branch information
MythicalCuddles committed Jan 18, 2020
1 parent f45e35d commit fd3b777
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions DiscordBot/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Discord.Addons.EmojiTools;

using DiscordBot.Common;
using DiscordBot.Exceptions;
using DiscordBot.Objects;

namespace DiscordBot.Extensions
Expand Down Expand Up @@ -298,10 +299,13 @@ public static bool HasHigherPermissionLevel(this IUser contextUser, IUser userMe
#region SocketUser Gets
public static SocketUser GetUser(this ulong id)
{
if (!(DiscordBot.Bot.GetUser(id) is SocketUser user))
var user = DiscordBot.Bot.GetUser(id);

if (user == null)
{
return null;
throw new UserNotFoundException("Unable to get the SocketUser assigned to the ID " + id);
}

return user;
}
#endregion
Expand Down

0 comments on commit fd3b777

Please sign in to comment.