From 104b938afc56da96e22083ec149c8efbb1e1b8c7 Mon Sep 17 00:00:00 2001 From: Sarah Faey Date: Thu, 1 Dec 2022 21:50:58 +0100 Subject: [PATCH] added try catch to avoid discord error message if renaming user is not possible --- DiscordBot/CommandHandlers/HandlerFunctions.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/DiscordBot/CommandHandlers/HandlerFunctions.cs b/DiscordBot/CommandHandlers/HandlerFunctions.cs index 378a191..974294c 100644 --- a/DiscordBot/CommandHandlers/HandlerFunctions.cs +++ b/DiscordBot/CommandHandlers/HandlerFunctions.cs @@ -58,15 +58,19 @@ namespace DiscordBot.CommandHandlers string nickname = $"{name} | {account}"; foreach(ulong serverId in serverList) { - SocketGuild guild = client.Guilds.FirstOrDefault(g => g.Id == serverId); - if(guild != null) + try { - SocketGuildUser user = guild.GetUser(userId); - if(user != null) + SocketGuild guild = client.Guilds.FirstOrDefault(g => g.Id == serverId); + if(guild != null) { - await user.ModifyAsync(p => p.Nickname = nickname); + SocketGuildUser user = guild.GetUser(userId); + if(user != null) + { + await user.ModifyAsync(p => p.Nickname = nickname); + } } } + catch {} } }