Skip to content

Commit a691a79

Browse files
committed
Ignore expected errors in bulk ban
1 parent c728357 commit a691a79

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

foxy/src/main/kotlin/net/cakeyfox/foxy/utils/AdminUtils.kt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import net.cakeyfox.serializable.data.utils.DiscordImageBody
2121
import net.cakeyfox.serializable.data.utils.DiscordMessageBody
2222
import net.dv8tion.jda.api.entities.User
2323
import net.dv8tion.jda.api.entities.UserSnowflake
24+
import net.dv8tion.jda.api.exceptions.ErrorResponseException
2425
import net.dv8tion.jda.api.exceptions.RateLimitedException
26+
import net.dv8tion.jda.api.requests.ErrorResponse
2527

2628
object AdminUtils {
2729
private val logger = KotlinLogging.logger {}
@@ -91,11 +93,9 @@ object AdminUtils {
9193
val guildData = foxy.database.guild.getGuild(guildId)
9294

9395
try {
94-
try {
95-
guild.ban(userAsSnowflakes, null)
96-
.reason(reason + " - ${staff.name} (${staff.id})")
97-
.await()
98-
} catch (e: Exception) { }
96+
guild.ban(userAsSnowflakes, null)
97+
.reason(reason + " - ${staff.name} (${staff.id})")
98+
.await()
9999

100100
val durationInstant =
101101
if (durationInMs > 0) Instant.fromEpochMilliseconds(
@@ -132,6 +132,19 @@ object AdminUtils {
132132
sendMessage(foxy, guildData, placeholders, guild)
133133
}
134134

135+
} catch (e: ErrorResponseException) {
136+
when (e.errorResponse) {
137+
ErrorResponse.FAILED_TO_BAN_USERS,
138+
ErrorResponse.UNKNOWN_BAN -> {
139+
// Already banned users can catch at this
140+
}
141+
142+
else -> {
143+
logger.error(e) {
144+
"Mass ban failed | guild=${guild.id} | users=${userAsSnowflakes.size} | staff=${staff.id}"
145+
}
146+
}
147+
}
135148
} catch (e: Exception) {
136149
logger.error(e) { "Failed to ban users on guild $guildId" }
137150
}

0 commit comments

Comments
 (0)