discordoauth
discordoauth copied to clipboard
Feature request: Guild Member object
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.
What exactly did it return? Was it just completely empty?
What have you tried so far up to this point?
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.
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.
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!
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.
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.
Ah, I missed that. Thanks!