More robust
This commit is contained in:
@@ -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})");
|
||||
Debug.WriteLine($"{count}/{total} User already has role, skipping. {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:");
|
||||
Debug.WriteLine(ex);
|
||||
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(100);
|
||||
await Task.Delay(800);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user