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