Skip to content

Commit

Permalink
add options to getUserGuilds
Browse files Browse the repository at this point in the history
  • Loading branch information
reboxer committed Dec 19, 2023
1 parent 8ce3003 commit 3d4339d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,20 @@ oauth.getUser(access_token).then(console.log);
*/
```

### `getUserGuilds(access_token)`
### `getUserGuilds(access_token, object)`

`access_token`: The user's access token.

Options:

`before`: Get guilds before this guild ID.

`after`: Get guilds after this guild ID.

`limit`: Max number of guilds to return (1-200).

`withCounts`: Include approximate member and presence counts in response.

Requires the `guilds` scope.

Returns a list of partial [guild](https://discord.com/developers/docs/resources/guild#guild-object) objects the current user is a member of.
Expand Down
9 changes: 8 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ declare namespace OAuth {
owner?: boolean;
permissions?: string;
features: string[];
approximate_member_count?: number;
approximate_presence_count?: number;
}

export interface Webhook {
Expand Down Expand Up @@ -165,7 +167,12 @@ declare class OAuth extends EventEmitter {
}): Promise<OAuth.TokenRequestResult>;
revokeToken(access_token: string, credentials?: string): Promise<string>;
getUser(access_token: string): Promise<OAuth.User>;
getUserGuilds(access_token: string): Promise<OAuth.PartialGuild[]>;
getUserGuilds(access_token: string, opts?: {
before?: string;
after?: string;
limit?: number;
withCounts?: boolean;
}): Promise<OAuth.PartialGuild[]>;
getUserConnections(access_token: string): Promise<OAuth.Connection[]>;
addMember(opts: {
deaf?: boolean;
Expand Down
32 changes: 25 additions & 7 deletions lib/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class OAuth extends RequestHandler {
options.disableLatencyCompensation,
// this looks horrible, probably should stop using prettier
// eslint-disable-next-line no-mixed-spaces-and-tabs
}
}
: {}),
});

Expand Down Expand Up @@ -154,15 +154,33 @@ class OAuth extends RequestHandler {
* Request all the guilds the user is in
* Requires the `guilds` scope
* @arg {String} access_token The user access token
* @arg {Object?} options The object containing the parameters for the request
* @arg {String?} options.before Get guilds before this guild ID
* @arg {String?} options.after Get guilds after this guild ID
* @arg {Number?} options.limit Max number of guilds to return (1-200)
* @arg {Boolean?} options.withCounts Include approximate member and presence counts in response
* @returns {Promise<Object[]>}
*/
getUserGuilds(access_token) {
return this.request("GET", "/users/@me/guilds", undefined, {
auth: {
type: "Bearer",
creds: access_token,
getUserGuilds(access_token, options = {}) {
const obj = {
before: options.before,
after: options.after,
limit: options.limit,
with_counts: options.withCounts,
};

return this.request(
"GET",
"/users/@me/guilds" +
(Object.keys(options).length ? `?${this._encode(obj)}` : ""),
undefined,
{
auth: {
type: "Bearer",
creds: access_token,
},
},
});
);
}

/**
Expand Down

0 comments on commit 3d4339d

Please sign in to comment.