added try catch to avoid discord error message if renaming user is not possible

This commit is contained in:
Sarah Faey 2022-12-01 21:50:58 +01:00
parent 26dd595057
commit 104b938afc

View file

@ -58,15 +58,19 @@ namespace DiscordBot.CommandHandlers
string nickname = $"{name} | {account}"; string nickname = $"{name} | {account}";
foreach(ulong serverId in serverList) foreach(ulong serverId in serverList)
{ {
SocketGuild guild = client.Guilds.FirstOrDefault(g => g.Id == serverId); try
if(guild != null)
{ {
SocketGuildUser user = guild.GetUser(userId); SocketGuild guild = client.Guilds.FirstOrDefault(g => g.Id == serverId);
if(user != null) 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 {}
} }
} }