Skip to content

Commit

Permalink
Merge pull request #68 from SFU-Dodo-Club/dev
Browse files Browse the repository at this point in the history
Automated Role Creating
  • Loading branch information
sarbjotm authored May 6, 2021
2 parents 484d338 + 42bd503 commit 44ba572
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cogs/moderator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import discord
from discord.ext import commands
import random
import os
from discord.ext.commands import has_permissions
from discord.utils import get
import re

pollOptions = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"]


class Moderator(commands.Cog):
def __init__(self, client):
self.client = client

@has_permissions(manage_roles=True)
@commands.command()
async def createrole(self, ctx, colour, *, role):
if get(ctx.guild.roles, name=f"{role}"):
await ctx.send("Role already exists")
return
regex = "^([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$"
p = re.compile(regex)
if re.search(p, str(colour)):
guild = ctx.guild
colour_of_role = '0x' + str(colour)
print(colour_of_role)
await guild.create_role(name=role, color=discord.Colour(int(f'{colour}', 16)))
print("role Created")
await ctx.send(f"{role} created with colour code {colour_of_role}")
else:
await ctx.send("Enter a valid hex colour code")


def setup(client):
client.add_cog(Moderator(client))

0 comments on commit 44ba572

Please sign in to comment.