async def get_role(self, ctx, *, role_name): """ Gives the user the requested custom role if not locked.. """ found_role = Role.where('name', role_name)\ .where('guild_id', ctx.guild.id).first() if found_role: if found_role.is_locked: await ctx.send("That custom role is currently locked and " "cannot assigned, if you believe this is an " "error then please contact an Admin") return discord_guild = self.bot.get_guild(found_role.guild_id) discord_role = discord_guild.get_role(found_role.role_id) if discord_role is None: await ctx.send("That custom role appears to be broken, " "please contact an admin") return await ctx.author.add_roles(discord_role) await ctx.send("You have been given the custom role " f"`{role_name}`") return for role in ctx.guild.roles: if lev.distance(role_name.lower(), role.name.lower()) <= 1: await ctx.send("That custom role does not exist but cannot be " "created as it's name is too similar to the " f"pre-existing role `{role.name}`") return result, _ = await ut.get_confirmation( ctx.channel, ctx.author, self.bot, "It looks like that custom role doesn't exist, " "would you like to create it?") if result: role = Role() role.name = role_name role.guild_id = ctx.guild.id role.created_by = ctx.author.id discord_role = await ctx.guild.create_role( name=role_name, mentionable=True, colour=Colour(random.choice(ROLE_COLOURS)), reason="Auto-Generated") role.role_id = discord_role.id role.save() await ctx.author.add_roles(discord_role) await ctx.send(f"You have been given the role {role_name}")