Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Guild Member object #17

Open
benthetechguy opened this issue Jul 23, 2022 · 7 comments
Open

Feature request: Guild Member object #17

benthetechguy opened this issue Jul 23, 2022 · 7 comments
Labels
Enhancement Issues relating to features/fixes that can enhance the code.

Comments

@benthetechguy
Copy link

benthetechguy commented Jul 23, 2022

I use this script in my website, and I want to check how long ago a user joined my server.
Looking at the Discord API, that information is accessible via the Guild Member object.
I attempted to add a function for get Guild Member based on the existing get_user function:

# A function to get user information within a guild | (identify scope)
function get_guild_member($guildid)
{
    $url = $GLOBALS['base_url'] . "/api/guilds/" . $guildid . "/members/" . $_SESSION['user_id'];
    $headers = array('Content-Type: application/x-www-form-urlencoded', 'Authorization: Bearer ' . $_SESSION['access_token']);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    $response = curl_exec($curl);
    curl_close($curl);
    $results = json_decode($response, true);
    $_SESSION['nick'] = $results['nick'];
    $_SESSION['user_guild_avatar'] = $results['avatar'];
    $_SESSION['roles'] = $results['roles'];
    $_SESSION['joined_at'] = $results['joined_at'];
    $_SESSION['deaf'] = $results['deaf'];
    $_SESSION['mute'] = $results['mute'];
    $_SESSION['permissions'] = $results['permissions'];
}

I didn't test any of the other values, but the joined_at one I wanted was empty, so I did something wrong.
Do you have any idea what I may have done wrong here? It would be excellent if this could be in the official script.

@Lil-Pandaa
Copy link
Contributor

What exactly did it return? Was it just completely empty?

What have you tried so far up to this point?

@benthetechguy
Copy link
Author

Yeah, it's just NULL. I tried adding a bot token and changing the authorization from Bearer to Bot, because I realized that api/guilds needs a bot token, as seen in get_guild. Unfortunately, it's still NULL.

@benthetechguy
Copy link
Author

The rabbit hole goes deeper. I discovered $_SESSION['user_id'] as used in $url is also NULL. I assumed I could use it, since join_guild does. Replacing it with a $userid argument, I'm getting "Missing Access" from Discord.

@f-o
Copy link
Collaborator

f-o commented Sep 21, 2022

Hello @benthetechguy.

Thanks for showing interest in the project, and wanting to further expand the possibilities of the script.
You were actually on the right track initially, as it is possible to get the Guild User object from the OAuth alone.

What you're looking for is this endpoint:
Get Current User Guild Member

To use this endpoint, please make sure you enable the scope guilds.members.read in your config.

You'd want to pass in the specific ID of the guild you want to return the object for.
Your function would look something like this:

function get_guild_member($id)
{
    $url = $GLOBALS['base_url'] . "/api/users/@me/guilds/$id/member";
    $headers = array('Content-Type: application/x-www-form-urlencoded', 'Authorization: Bearer ' . $_SESSION['access_token']);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    $response = curl_exec($curl);
    curl_close($curl);
    $results = json_decode($response, true);
    return $results;
}

This will return the values from the Guild Member Object, where you can find the ISO8601 timestamp in the joined_at key.

Hope this helps, and we will be sure to add this to the demo!

@f-o f-o added the Enhancement Issues relating to features/fixes that can enhance the code. label Sep 21, 2022
@benthetechguy
Copy link
Author

Perfect, that worked!

By the way, what terms can I use this software under? I use it in my website, but there is no license, so it's unclear what I can do with it. I made an issue #16 and it was said that a license would be added, but it's been months and there is no license yet.

@f-o
Copy link
Collaborator

f-o commented Sep 21, 2022

By the way, what terms can I use this software under?

I did actually get a chance to chat with Markis about a license for this project back in May, as per your request in the issue.
We decided that the MIT License would be very suiting for a project like this.

While we found a solution, it seems that there was a bit of miscommunication, and the issue was closed without an actual implementation. I apologize for that.

A couple of hours ago this was fixed, and this project is now properly licensed.

@benthetechguy
Copy link
Author

benthetechguy commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Issues relating to features/fixes that can enhance the code.
Projects
None yet
Development

No branches or pull requests

3 participants