More robust

This commit is contained in:
2025-12-13 20:03:21 +01:00
parent ea818ee184
commit 6e152e3d0a

View File

@@ -202,18 +202,29 @@ public class SlashCommands(GatewayClient client) : ApplicationCommandModule<Appl
foreach (var user in users) foreach (var user in users)
{ {
count++; count++;
try if (user.RoleIds.Contains(roleId))
{ {
await client.Rest.AddGuildUserRoleAsync(GuildId, user.Id, roleId); Debug.WriteLine($"{count}/{total} User already has role, skipping. {user.Username} ({user.Id})");
Debug.WriteLine($"{count}/{total} Applied role to user {user.Username} ({user.Id})"); continue;
} }
catch (Exception ex)
for (int i = 0; i < 3; i++)
{ {
Debug.WriteLine($"{count}/{total} Failed to apply role to user {user.Username} ({user.Id}). Error:"); try
Debug.WriteLine(ex); {
await client.Rest.AddGuildUserRoleAsync(GuildId, user.Id, roleId);
Console.WriteLine($"{count}/{total} Applied role to user {user.Username} ({user.Id})");
break;
}
catch (Exception ex)
{
Console.WriteLine($"{count}/{total} Failed to apply role to user {user.Username} ({user.Id}). Try {i}/3. Error:");
Console.WriteLine(ex);
await Task.Delay(800);
}
} }
await Task.Delay(100); await Task.Delay(800);
} }
} }