commands.color_role_commands module

commands.color_role_commands.is_valid_hex_color(hex_color)[source]

Validate if a string is a valid hex color code.

Parameters:

hex_color (str) – String to validate (with or without # prefix)

Returns:

True if valid hex color, False otherwise

Return type:

bool

commands.color_role_commands.hex_to_discord_color(hex_color)[source]

Convert hex color string to Discord Color object.

Parameters:

hex_color (str) – Hex color string (with or without # prefix)

Returns:

Discord color object

Return type:

discord.Color

commands.color_role_commands.find_existing_color_role(guild, hex_color)[source]

Find an existing role with the same hex color name.

Parameters:
  • guild (Guild) – Discord guild to search in

  • hex_color (str) – Hex color string to search for

Returns:

Existing role if found, None otherwise

Return type:

discord.Role | None

async commands.color_role_commands.get_lowest_position(_guild)[source]

Get the lowest position for placing color roles at the bottom of hierarchy.

Parameters:

guild – Discord guild

Returns:

Position for new color role (just above @everyone)

Return type:

int

async commands.color_role_commands.create_color_role(guild, hex_color, _bot_member)[source]

Create a new color role with the specified hex color.

Parameters:
  • guild (Guild) – Discord guild to create role in

  • hex_color (str) – Hex color string

  • bot_member – Bot’s member object for permission checking

Returns:

The created role

Return type:

discord.Role

Raises:
async commands.color_role_commands.remove_existing_color_roles(member)[source]

Remove all existing color roles from a member.

Parameters:

member (Member) – Discord member to remove color roles from

Returns:

List of removed role names

Return type:

list[str]

async commands.color_role_commands.validate_color_role_request(interaction, hex_color)[source]

Validate a color role request.

Parameters:
  • interaction (Interaction) – Discord interaction

  • hex_color (str) – Hex color string to validate

Returns:

(is_valid, error_message)

Return type:

tuple[bool, str | None]

async commands.color_role_commands.get_assignable_roles_from_db(guild_id)[source]

Get assignable roles from the Django database.

Parameters:

guild_id (int) – Discord guild ID

Returns:

List of assignable role data from database

Return type:

list[dict]

async commands.color_role_commands.assignable_role_autocomplete(interaction, current)[source]

Autocomplete function for assignable role names.

Return type:

list[Choice[str]]

commands.color_role_commands.setup_basic_color_commands(bot)[source]

Set up basic color role commands (role, remove_role).

async commands.color_role_commands.assign_server_role(interaction, role_id)[source]

Handle assignable role assignment logic.

async commands.color_role_commands.assign_hex_color_role(interaction, hex_color, bot)[source]

Handle hex color role assignment logic.

commands.color_role_commands.setup_remove_role_command(bot)[source]

Set up the remove_role command.

async commands.color_role_commands.remove_specific_role(interaction, role_id)[source]

Handle removal of a specific assignable role.

async commands.color_role_commands.remove_color_roles(interaction)[source]

Handle removal of color roles.

commands.color_role_commands.setup_assign_role_command(bot)[source]

Set up the assign_role command.

commands.color_role_commands.setup_unassign_role_command(bot)[source]

Set up the unassign_role command.

commands.color_role_commands.setup_list_roles_command(bot)[source]

Set up the list_roles command.

commands.color_role_commands.setup_color_role_commands(bot)[source]

Set up all color role and assignable role commands.