logoCustom Commands
    BlogPrivacyPremiumSupport
Back to blog
// blog

Add or remove role from mentioned user using custom commands bot

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

Md Shahriyar Alam

2 years ago

·1 min read

Custom Commands 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.

py
# 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, ccbot.appManage permissions of custom slash commands

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

py
require_permission("administrator")

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

Final code

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

Loading comments…

{}

Need help?

Have a question, a suggestion, or stuck on something? Reach out — we're happy to help.

DiscordJoin support server
logoCustom Commands

The #1 custom commands Discord bot — build commands, events and databases with zero boilerplate.

stripe

Links

HomeBlogPrivacySupport

Contact

[email protected]

2 Frederick StreetLondon, WC1X 0ND

{ / } custom commands

© WEiRDSOFT LTD. All rights reserved.