cogs/color/management.py
async def add_color(self, ctx, hexcode, *, name=""):
        """Add a color to the database colors."""
        colors = db.get(ctx.guild.id, "colors")

        if len(colors) >= cfg.color_limit:
            raise CommandError(f"Color Limit Reached ({len(colors)}/50)")

        if not utils.validate_hex(hexcode):
            raise UserInputError(
                f"Invalid hexcode. Get help at https://htmlcolorcodes.com/")

        if "|" in name or len(name) > 100:
            raise UserInputError(
                "Color names must be shorter than 100 characters and cannot include `|`")

        if name in [color["name"] for color in colors]:
            raise UserInputError("Cannot have duplicate color names")

        # auto name if name not given
        if not name:
            name = f"Color {len(colors) + 1}"

        # change black color because #000000 in discord is transparent
        if hexcode in {"#000000", "#000"}:
            hexcode = "#000001"

        # create and add color
        new_color = {
            "name": name,
            "hexcode": hexcode,
            "role": None,
            "members": []
        }

        # update database
        db.guilds.update_one(
            {"_id": ctx.guild.id},
            {"$push": {"colors": new_color}}
        )
        await ctx.invoke(bot.get_command("colors"))
Add a color to the database colors.
Add a color to the database colors.
Add a color to the database colors .
async def add_color(self, ctx, hexcode, *, name=""):
        colors = db.get(ctx.guild.id, "colors")
        if len(colors) >= cfg.color_limit:
            raise CommandError(f"Color Limit Reached ({len(colors)}/50)")
        if not utils.validate_hex(hexcode):
            raise UserInputError(
                f"Invalid hexcode. Get help at https://htmlcolorcodes.com/")
        if "|" in name or len(name) > 100:
            raise UserInputError(
                "Color names must be shorter than 100 characters and cannot include `|`")
        if name in [color["name"] for color in colors]:
            raise UserInputError("Cannot have duplicate color names")
        if not name:
            name = f"Color {len(colors) + 1}"
        if hexcode in {"#000000", "#000"}:
            hexcode = "#000001"
        new_color = {
            "name": name,
            "hexcode": hexcode,
            "role": None,
            "members": []
        }
        db.guilds.update_one(
            {"_id": ctx.guild.id},
            {"$push": {"colors": new_color}}
        )
        await ctx.invoke(bot.get_command("colors"))
async def add_color ( self , ctx , hexcode , * , name = "" ) : colors = db . get ( ctx . guild . id , "colors" ) if len ( colors ) >= cfg . color_limit : raise CommandError ( f"Color Limit Reached ({len(colors)}/50)" ) if not utils . validate_hex ( hexcode ) : raise UserInputError ( f"Invalid hexcode. Get help at https://htmlcolorcodes.com/" ) if "|" in name or len ( name ) > 100 : raise UserInputError ( "Color names must be shorter than 100 characters and cannot include `|`" ) if name in [ color [ "name" ] for color in colors ] : raise UserInputError ( "Cannot have duplicate color names" ) if not name : name = f"Color {len(colors) + 1}" if hexcode in { "#000000" , "#000" } : hexcode = "#000001" new_color = { "name" : name , "hexcode" : hexcode , "role" : None , "members" : [ ] } db . guilds . update_one ( { "_id" : ctx . guild . id } , { "$push" : { "colors" : new_color } } ) await ctx . invoke ( bot . get_command ( "colors" ) )
Add a color to the database colors.
Add a color to the database colors .
"""Add a color to the database colors.""" # auto name if name not given # change black color because #000000 in discord is transparent # create and add color # update database
self
ctx
hexcode
name