-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace deleted roles counter with list of deleted roles
- Loading branch information
Showing
2 changed files
with
20 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
import discord | ||
from util import errorAndRespond, logAndRespond, logError | ||
from util import delete_role, errorAndRespond, logAndRespond | ||
|
||
|
||
async def clean_empty_color_roles(ctx: discord.ApplicationContext): | ||
try: | ||
assert ( | ||
type(ctx.guild) is discord.Guild | ||
), "Encountered an issue accessing the Discord guild" | ||
|
||
empty_color_roles = [ | ||
role | ||
for role in ctx.guild.roles | ||
if role.name.startswith("#") and len(role.members) == 0 | ||
] | ||
counter = 0 | ||
for role in empty_color_roles: | ||
try: | ||
await role.delete() | ||
counter += 1 | ||
except: | ||
logError(f"Failed to delete role {role.name}") | ||
return await logAndRespond(ctx, f"Cleaned up {counter} empty color roles!") | ||
deleted_roles: list[str] = [ | ||
role.name for role in empty_color_roles if delete_role(role) | ||
] | ||
|
||
return await logAndRespond( | ||
ctx, | ||
f"Cleaned up {len(deleted_roles)} empty color roles:\n" | ||
+ "\n".join(deleted_roles), | ||
) | ||
except AssertionError as errorMessage: | ||
return await errorAndRespond(ctx, errorMessage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters