Role Functions
This part isn't hard, but useful when multiple choices for different roles are needed
Preface
These functions are useful with if-else
function. Read the following codes:
Everyone must know the meaning of the codes above. If the triggering user has the role A whose ID is ########
, it will determine whether the user has another role B whose ID is &&&&&&&&&&&
, give the role B if the user doesn't have it, and remove the role A from the user; if the triggering user doesn't have role A, the bot will automatically give him (her) the role A.
The functions can also be used like the following codes (different roles can read different contents):
Function
Function
Description
addRoleID roleID
Adds the role with the given ID to the user that triggered the command (use the listroles
command for a list of roles).
giveRoleID userID roleID
Gives a role by ID to the target.
giveRoleName userID "roleName"
Gives a role by name to the target.
hasRoleID roleID
Returns true if the user has the role with the specified ID (use the listroles command for a list of roles).
hasRoleName "rolename"
Returns true if the user has the role with the specified name (case-insensitive).
removeRoleID roleID (delay)
Removes the role with the given ID from the user that triggered the command (use the listroles command for a list of roles). Delay
is optional argument in seconds.
takeRoleID userID roleID (delay)
Takes away a role by ID from the target. Delay
is optional argument in seconds.
takeRoleName userID "roleName" (delay)
Takes away a role by name from the target. Delay
is optional argument in seconds.
targetHasRoleID userID roleID
targetHasRoleName userID "roleName"
Returns true if the given user has the role with the specified name (case-insensitive).
Example:
To demonstrate usage of
targetHasRoleID
. >{{$x := (userArg (index .Args 1)).ID}} {{if targetHasRoleID $x ############}} Has the Role! {{else}} Does not have the role! {{end}}
Last updated
Was this helpful?