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++;
if (user.RoleIds.Contains(roleId))
{
Debug.WriteLine($"{count}/{total} User already has role, skipping. {user.Username} ({user.Id})");
continue;
}
for (int i = 0; i < 3; i++)
{
try try
{ {
await client.Rest.AddGuildUserRoleAsync(GuildId, user.Id, roleId); await client.Rest.AddGuildUserRoleAsync(GuildId, user.Id, roleId);
Debug.WriteLine($"{count}/{total} Applied role to user {user.Username} ({user.Id})"); Console.WriteLine($"{count}/{total} Applied role to user {user.Username} ({user.Id})");
break;
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.WriteLine($"{count}/{total} Failed to apply role to user {user.Username} ({user.Id}). Error:"); Console.WriteLine($"{count}/{total} Failed to apply role to user {user.Username} ({user.Id}). Try {i}/3. Error:");
Debug.WriteLine(ex); Console.WriteLine(ex);
await Task.Delay(800);
}
} }
await Task.Delay(100); await Task.Delay(800);
} }
} }