Add or remove role from mentioned user

Md Shahriyar Alam

09-02-2023

To remove role from mentioned user use the add_roles and remove_roles variable

Command setup

First of all we need to add an argument/option to our command, where we can mention the user we want to remove roles. So go ahead and add an option, name it target and select MEMBER as the type then type anything relavent in the description. Maybe The target member

Code

Now we have to write code in the the Hooks (pre) to add roles to the mentioned user.

# Example 1
add_roles(target, role_id)

# Example 2
add_roles(target, role_id, another_role_id)

In example 1 we just added 1 role to the target and in example 2 we have added 2 roles to the target, We can actually add any amount of roles to the target, Just add another role id at the end followed by a comma (,).

Removing role works the same way, Just replace add_roles with remove_roles, others are same. You can use both of them at a same time in the same command.

Note: Make sure to properly manage permission of the command so that not everyone can use this command. You can see how we can manage permissions of a command in this blog, Manage permissions of custom slash commands

Or you can just put the code below for basic permission management

require_permission("administrator")

Just put this line of code above the add_roles/remove_roles code.

Final code

require_permission("administrator")
add_roles(target, role_id, another_role_id)

Need help?

If you still need any kind of help, have a suggestion for us or having a question in mind? Feel free to reach us out.

Join support server
logoCustom Slash Commands

#1 Custom Slash commands bot available on the internet

We Accept

stripe

Contact

20-22 Wenlock RoadEnglandN1 7GU

© WEiRDSOFT LTD. All rights reserved.