Added Cog for role managment
This commit is contained in:
parent
a43b21d853
commit
cc214cb1ab
2 changed files with 36 additions and 0 deletions
35
cogs/roles.py
Normal file
35
cogs/roles.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import discord
|
||||
import data
|
||||
from discord.ext import commands
|
||||
from discord.utils import get
|
||||
|
||||
ROLES_JSON = "roles"
|
||||
|
||||
class Roles(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@discord.slash_command()
|
||||
@discord.default_permissions(manage_roles=True)
|
||||
async def addsecretrole(self, ctx, role: discord.role.Role, password: str):
|
||||
roles = data.load_data(ROLES_JSON)
|
||||
if password in roles["secret_roles"]:
|
||||
return await ctx.respond(f"Password ``{password}`` is already used.", ephemeral=True)
|
||||
|
||||
roles["secret_roles"][password] = role.id
|
||||
data.dump_data(ROLES_JSON, roles)
|
||||
return await ctx.respond(f"Secret role {role.mention} added with password {password}.", ephemeral=True)
|
||||
|
||||
@discord.slash_command()
|
||||
async def secretrole(self, ctx, password: str):
|
||||
roles = data.load_data(ROLES_JSON)
|
||||
if password in roles["secret_roles"]:
|
||||
author = ctx.author
|
||||
role = get(author.guild.roles, id=roles["secret_roles"][password])
|
||||
await author.add_roles(role, reason="Roles assigned for password knowledge.")
|
||||
return await ctx.respond(f"You now have role {role.mention}.", ephemeral=True)
|
||||
else:
|
||||
return await ctx.respond("Incorrect password.", ephemeral=True)
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Roles(bot))
|
1
main.py
1
main.py
|
@ -7,6 +7,7 @@ bot = commands.Bot()
|
|||
|
||||
cogs_list = [
|
||||
'basic',
|
||||
'roles',
|
||||
]
|
||||
|
||||
for cog in cogs_list:
|
||||
|
|
Loading…
Reference in a new issue