Creating a json in my server with a few user details

#1

Hello,

I have built a discord bot in python that procedurally generates images for tabletop roleplaying games. I would like my patrons to, according to their pledge levels, have access to special commands avaliable to them in any discord servers that host my bot.

I was wondering what the best way of checking for that was. I imagine if the bot was only in my server I could check for their role, but that wouldn’t work in other servers. So perhaps creating a json file that my bot could access to that gets updated with new pledges (or every hour, I don’t know if it can get automatically updated if a user adds their discord info to their profile) and compare the discord user executing the command to the list of patrons in the json… but I honestly have no idea how to do that.

Any help with that method or something else that could work would be greatly appreciated!

0 Likes

#2

Hi @PSNick!

You can check the pledge endpoint periodically (e.g. every hour, as you said) and get user data off of that to get discord info. The pledge resource has a relationship to user.

To get user details, you need to include the user (add a query param for include=patron). In addition, you need to specify which fields to include (another query param fields[user]=social_connections,first_name,last_name,... . See https://docs.patreon.com/#user-v2 for which fields can be requested on the user object and https://docs.patreon.com/#resources for an explanation of the JSON:API standard for requesting includes/fields.

Discord information can be found in the social_connections field in the user.

Please reach out if you have further questions!

Evy
Platform Engineer

2 Likes

#3

Thank you for the help evy!

I managed to get it working a day or two after I posted (I should have updated, my bad!). From what I read once it passes 20 members there will be ‘pages’ of user information? I haven’t coded anything for that just yet, though I’m halfway there in the member count. Any tips on how to include this pagination in the code?

Thank you!

0 Likes

#4

No worries - glad you were able to get it working!

Yup, our members are paginated. You can read a bit more about that in our documentation, the jsonapi docs, and see an example for jsonapi here.

This documentation also looks pretty sweet: https://laravel-json-api.readthedocs.io/en/latest/fetching/pagination/

Please reach out if you have further questions!

Evy
Platform Engineer

0 Likes