Discordroles - a proper attempt this time

cant say im not proud of my last discord roles resource. the code was beyond shabby and had many things i just didnt think about. so i tried to fix that.

NOTE: THIS WILL NOT FUNCTION AS A PLUG N PLAY FOR RESOURCES DEPENDING ON discord_roles. THIS IS A COMPLETE REWORK AND WILL REQUIRE THE RESOURCE DEPENDING ON IT TO BE UPDATED OR MODIFIED.

attempt 2

this resource is just an improvement to the old version, however the implementation is a lot different, so i dont expect many people to really adapt it to what already exists sadly.

The standard rule for each export is as follows:

  • guild is an optional value that will take a custom guild ( a guild different to the one defined in your config.json )
  • role can be an array/table or a string. if array, it simply checks to see if any of the items match any roles in the users roles.

The current exports available are:

  • isRolePresent(user, role, guild, callback) / isRolePresent(user, role, callback)
  • getUserRoles(user, guild, callback) / getUserRoles(user, callback)
  • getUserData(user, guild, callback) / getUserData(user, callback)

example:

( note: the first param is the users id, but im using discordid here as an example )

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)

for zap users - see here on a solution for any issues

14 Likes

I love your current implemintation but its got that one bug where if two connect at the same time it can mix up the roles. Does this work with the aceperms and such also? I am going to try it on my dev server and find out tonight.

But I do want to say Thank you for all you do, because it helps!

1 Like

You never needed one of these resources for ace permissions. You just write the ACE out…

1 Like

(hasRole and 'true' or 'false')
?

1 Like

why a question mark? this was just for the example to be able to print the bool

hasRole is a boolean itself, so in theory (don’t know about lua) you can just print hasRole no need to check if it’s true or false

the whole reason i did that was because you cant concat a bool with a string in Lua it seems.

https://www.lua.org/manual/5.3/manual.html#pdf-tostring

1 Like

ooo, havent used lua in a while tbf, only use was for the example :stuck_out_tongue:

1 Like

Hi there,
I am getting the following issue

"[discordroles] requqest to discord API failed.

  • 404 : the resource at the location specified doesn’t exist."

While I’m using the example code, with my personal role id

Could anyone help me please?
(I did put the guild & tokens correctly)

If anyone will run into Discord rate limit error (429), just know that request limit is 5 requests in about one second, so you need to request at least every 200ms (at least it was for me).

That’s just some information on which I had to do little research and testings, hope it helps someone.

having a 404 would mean that some data is missing, are you sure your guild id is correct, can you show me an example or so? try turn on debug mode in the config and seeing the prints, and send em over if possible.

1 Like

I’m not providing any help for the old version not am I the creator of discord whitelist, you’d be better off contacting them.

I tried to send this morning but for some reason my message got removed.

but here’s a screenshot:

(This is the link it refers to)


This made me think it was due to the bot’s roles, but he has a role with administrator rights so that shouldn’t be it…

And the piece of code:

I double checked thrice and the guildid - bot token and the role id are 100% correct…

ohhh, i think it could be related to the user not being in the guild i suspect. axios catches any statuscode outside of 2** so it fell into the error category.

this should be fixed now. updating the example to match this new change

This isn’t possible tho, I am using DisordWhitelist (with your older version)
And its happening for every single user (including myself, and I am defo in the guild ^^ )

Edit:
Forgot to mention that I will try this tomorrow, I’m heading off rn and I’ll keep you updated tomorrow.

then are you sure the guildid is correct?

Looking good. Was having quite a few issues with v1 as you stated when you closed it that it caused quite a few issues. Hoping to start work on rewritting my server’s permissions systems with this.

Thanks, Keep up the good work!

Guild id is just the server id right?

If so then yes I am 100% sure,
I have copied id through discord developer mode, I am using the same guild id in the old version, I have copied the id (which is the same) from the webhooks section as well etc

And when the script initializes it says the name of my bot etc so that should work too…