pawn Code:
new DCC_Role:role, rolename[128];//<<<<<<<<<<<<<<<<<<<<
DCC_GetRoleName(role, rolename, 128);//<<<<<<<<<<<<<<<<<<<<
No this isn't correct.
DCC_GetRoleName will copy the name of the specified role (the variable named 'role') to the array you pass it (rolename in this case) howewer, as you just created the variable 'role' it currently holds the value 'DCC_Role:0', which if you check discord-connector.inc is an invalid role
pawn Code:
#define DCC_INVALID_ROLE DCC_Role:0
You need to retrieve the role(s) of the author of the message, for this, discord-connector has the function
pawn Code:
'native DCC_GetGuildMemberRole(DCC_Guild:guild, DCC_User:user, offset, &DCC_Role:role);'
A bot (and a user) can be in many guilds (discord servers) so you need to specify for which server you want to get that user's roles. To retrieve your guild you may use:
pawn Code:
native DCC_Guild:DCC_FindGuildById(const guild_id[]);
This will return the guild that you should use to call 'DCC_GetGuildMemberRole'
Now, a user may have many roles not just one, so you need to retrieves all of the roles and compare each with the allowed roles for the command.
This is what the third parameter of 'DCC_GetGuildMemberRole' ('offset') is for. If offset is 0 you will get the first role of this user, if is 1 you will get the second role, etc. To know how many roles the user has use:
pawn Code:
native DCC_GetGuildMemberRoleCount(DCC_Guild:guild, DCC_User:user, &count);
Then you just need to loop through each of the user's role
Finally the code would look something like this:
pawn Code:
//optionally you may prefer to make 'DCC_Guild:guild' global and call 'DCC_FindGuildById' in OnGamemodeInit
//so that it only gets called once and not each time someone uses a command
new
DCC_Guild:guild = DCC_Guild:DCC_FindGuildById("yourGuildId"),
roleCount,
DCC_Role:role;
DCC_GetGuildMemberRoleCount(guild, author, roleCount);
if(channel == g_Discord_Admin_CMD) {
if(!strcmp(command, "!mycommand", true)) {
//Loop through all roles for this user
for(new i = 0; i < roleCount; i++) {
DCC_GetGuildRole(guild, i, role);
//you can compare 'role' directly to 'g_Role_Level_X'
if(role == g_Role_Level_1 || role == g_Role_Level_2 || role == g_Role_Level_3 || role == g_Role_Level_4) {
//My actions
//if you don't break here the command may execute many times. for example if user has both g_Role_Level_1 and g_Role_Level_3
break;
} else return DCC_SendChannelMessage(g_Discord_Admin_CMD, "```ERROR: You are not a high enough level to use this command```");
}
}
//other commands
}