From 08e70bc9593b0556e32a587269fb5cbc50eb96b4 Mon Sep 17 00:00:00 2001 From: EdVraz <88881326+EdVraz@users.noreply.github.com> Date: Sat, 13 Nov 2021 19:26:23 +0100 Subject: [PATCH] user roles - add - remove --- cogs/server_utils.py | 46 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/cogs/server_utils.py b/cogs/server_utils.py index d129fd7..97c25fb 100644 --- a/cogs/server_utils.py +++ b/cogs/server_utils.py @@ -744,8 +744,50 @@ async def _unban(self, ctx: SlashContext, user_id: str, await ctx.send(f"unbanned {user.mention}!") # @cog_ext.cog_subcommand(base="server", subcommand_group="user", name="un-punish", description="un-punishes a user") - # @cog_ext.cog_subcommand(base="server", subcommand_group="user", name="add-role", description="adds a role to a user") - # @cog_ext.cog_subcommand(base="server", subcommand_group="user", name="remove-role", description="removes a role from a user") + + radd_opt = [ + { + "name": "user", + "description": "the user to add the role to", + "required": True, + "type": 6, + }, + { + "name": "role", + "description": "the role to add", + "type": 8 + } + ] + + @cog_ext.cog_subcommand(base="server", subcommand_group="user", name="add-role", + description="adds a role to a user", options=radd_opt) + async def _role_add(self, ctx: SlashContext, user: discord.Member, role: discord.Role): + if not ctx.author.guild_permissions.manage_roles: + raise discord.ext.commands.MissingPermissions(missing_perms=["manage_roles"]) + await user.add_roles([role]) + await ctx.send("Done!") + + rrem_opt = [ + { + "name": "user", + "description": "the user to remove the role from", + "required": True, + "type": 6, + }, + { + "name": "role", + "description": "the role to remove", + "type": 8 + } + ] + + @cog_ext.cog_subcommand(base="server", subcommand_group="user", name="remove-role", + description="removes a role from a user", options=rrem_opt) + async def _role_remove(self, ctx: SlashContext, user: discord.Member, role: discord.Role): + if not ctx.author.guild_permissions.manage_roles: + raise discord.ext.commands.MissingPermissions(missing_perms=["manage_roles"]) + await user.remove_roles([role]) + await ctx.send("Done!") rcre_opt = [ {