diff --git a/README.md b/README.md index 12f2c73..6aff62b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/index.d.ts b/index.d.ts index f8a51bd..7d9ea93 100644 --- a/index.d.ts +++ b/index.d.ts @@ -90,6 +90,8 @@ declare namespace OAuth { owner?: boolean; permissions?: string; features: string[]; + approximate_member_count?: number; + approximate_presence_count?: number; } export interface Webhook { @@ -165,7 +167,12 @@ declare class OAuth extends EventEmitter { }): Promise; revokeToken(access_token: string, credentials?: string): Promise; getUser(access_token: string): Promise; - getUserGuilds(access_token: string): Promise; + getUserGuilds(access_token: string, opts?: { + before?: string; + after?: string; + limit?: number; + withCounts?: boolean; + }): Promise; getUserConnections(access_token: string): Promise; addMember(opts: { deaf?: boolean; diff --git a/lib/oauth.js b/lib/oauth.js index 5da0547..c408f1c 100644 --- a/lib/oauth.js +++ b/lib/oauth.js @@ -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 - } + } : {}), }); @@ -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} */ - 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, + }, }, - }); + ); } /**