Add or remove role from mentioned user using custom commands bot

Md Shahriyar Alam

2 months ago

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

pyrequire_permission("administrator")

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

Final code

pyrequire_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.

DiscordJoin support server
logoCustom Commands

#1 Custom commands discord bot available on the internet

stripe

Contact

20-22 Wenlock RoadEnglandN1 7GU

© WEiRDSOFT LTD. All rights reserved.