Discordroles - a proper attempt this time

i just realised, in your isRolePresent, there is meant to be 2 string parameters (or a table), the first one being the user/user discord id, then the second being the roleid to search for

1 Like

Ohhh my bad, I didnā€™t knowā€¦

I changed the script to look for the discord identifier as well now, and this works!

Thank you for your support!
You seem like a cool guy :wink:

Hello there.

Why is it that this error is showing on my console? Thank you.

SCRIPT ERROR: citizen:/scripting/lua/scheduler.lua:901: No such export IsRolePresent in resource discordroles

because you need to actually change the export name to match whatever you called the resource

this is how inserted it.

local hasPerms = exports['discordroles']:isRolePresent(source, '712682067502301184')

is this correct?

have you actually got my resource named as ā€œdiscordrolesā€ in the resources folder? you need to change that string if not.

1 Like

yes it is named as it is.

the error mentions IsRolePresent, while the export is isRolePresent, theres no capital at the start.

not only this, your implementation for this version is incorrect. You need a callback in this version as it is different to my old version.

Thank you i finally make it work!

Hey, so, I understand how the export and all works. However I seem to be having an issue, whereby, whenever I implement it into my code (a discord chat roles), it just doesnā€™t work, and no one has any tag. Now this could be me being an idiot, or idek. But any help would be appreciated.

server.lua

local Ranks = {

Owner = {

    id = '736995810381660301',

    display = "^4Owner ^0|^7 "

},

CoOwner = {

    id = '736999336784953396',

    display = "^5Co-Owner ^0|^7 "

},

ComManager = {

    id = '750474818012577894',

    display = "^3Community Manager ^0|^9 "

},

SeniorAdmin = {

    id = '750439216856694924',

    display = "^6Senior Admin ^7|^0 "

},

Admin = {

    id = '750439216038805574',

    display = "^8Admin ^7| "

},

Moderator = {

    id = '736995817591668780',

    display = "^1Moderator ^7|^0 "

},

Probey = {

    id = '736995818414014485',

    display = "^9Probationary Staff ^0|^8 "

},

Developer = {

    id = '753021921268072528',

    display = "Developer ^7| "

},

TextureDev = {

    id = '[insert]',

    display = "Developer ^7| "

},

ServerBooster = {

    id = '750113164774998027',

    display = "^6Server Booster ^7|^0 "

}

}

AddEventHandler(ā€˜chatMessageā€™, function(Source, Name, Msg)

local args = stringsplit(Msg, " ")

CancelEvent()

if string.find(args[1], "/") then

    table.remove(args, 1)

else

    if exports['discordroles']:isRolePresent(Source, {Ranks.Owner.id} then

        TriggerClientEvent('chatMessage', -1, Rank.Owner.display .. Name, {255, 255, 255}, Msg)

    elseif exports['discordroles']:isRolePresent(Source, {Rank.CoOwner.id} then

        TriggerClientEvent('chatMessage', -1, Rank.CoOwner.display .. Name, {255, 255, 255}, Msg)

    elseif exports['discordroles']:isRolePresent(Source, {Ranks.ComManager.id} then

        TriggerClientEvent('chatMessage', -1, Rank.ComManager.display .. Name, {255, 255, 255}, Msg)

    elseif exports['discordroles']:isRolePresent(Source, {Rank.SeniorAdmin.id} then

        TriggerClientEvent('chatMessage', -1, Rank.SeniorAdmin.display .. Name, {255, 255, 255}, Msg)

    elseif exports['discordroles']:isRolePresent(Source, {Rank.Admin.id} then

        TriggerClientEvent('chatMessage', -1, Rank.Admin.display .. Name, {255, 255, 255}, Msg)

    elseif exports['discordroles']:isRolePresent(Source, {Ranks.Moderator.id} then

        TriggerClientEvent('chatMessage', -1, Rank.Moderator.display .. Name, {255, 255, 255}, Msg)

    elseif exports['discordroles']:isRolePresent(Source, {Rank.Probey.id} then

        TriggerClientEvent('chatMessage', -1, Rank.Probey.display .. Name, {255, 255, 255}, Msg)

    elseif exports['discordroles']:isRolePresent(Source, {Rank.Developer.id} then

        TriggerClientEvent('chatMessage', -1, Rank.Developer.display .. Name, {205, 205, 205}, Msg)

    elseif exports['discordroles']:isRolePresent(Source, {Ranks.TextureDev.id} then

        TriggerClientEvent('chatMessage', -1, Rank.TextureDev.display .. Name, {205, 205, 205}, Msg)

    elseif exports['discordroles']:isRolePresent(Source, {Rank.ServerBooster.id} then

        TriggerClientEvent('chatMessage', -1, Rank.ServerBooster.display .. Name, {255, 255, 255}, Msg)

    else

        TriggerClientEvent('chatMessage', -1, Name, {255, 255, 255}, Msg)

    end

end

end)

function stringsplit(inputstr, sep)

if sep == nil then

sep = "%s"

end

local t={} ; i=1

for str in string.gmatch(inputstr, ā€œ([^ā€ā€¦sepā€¦"]+)") do

t[i] = str

i = i + 1

end

return t

end

See the example on the OP

exports['discordroles']:isRolePresent('138725221749358592', {'749808671558729729'} --[[ can be a table or just a string. ]], function(hasRole, roles)
  if (not roles) then print("user not in guild") end --roles will be null if no user can be found, suggesting they arent in the guild
  print('userHasRole: '..(hasRole and 'true' or 'false'))
  print('roles: '..json.encode(roles))
end)

It returns two values hasRole & roles. Youā€™re not checking for either of these values.

How do you check multiple role?

Use arrays

@sadboilogan Does it work on linux?

It works on Linux.

Hey together,
i started to use the Ressource on my Server.
Give it the Token of my Added Bot, and linked the Role IDs.
Know the Debug Mode gives me this Error:Error
Hope you can help me.

Seems the resource is not installed correctly.

Try this https://docs.faxes.zone/docs/discordroles

(Not official docā€™s but will work for ya)

Worked for me, thank you for the guide :slightly_smiling_face: y

Screenshot_131

This seem to happen when the person has discord running as administrator.