@theholocron/discord-client 1.48.0 → 1.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -101,7 +101,7 @@ the create response.
101
101
 
102
102
  | Resource | Methods |
103
103
  | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
104
- | `client.users` | `me()` — `GET /users/@me`, a cheap token check; `get(id)` — a user's name |
104
+ | `client.users` | `me()` — `GET /users/@me`, a cheap token check; `get(id)` — a user's name; `guilds({ limit, after })` — `GET /users/@me/guilds`, the servers the bot is in and whether it owns each (look here before retrying `guilds.create`) |
105
105
  | `client.application` | `get`, `modify` (the bot's own application: description, tags, install settings, URLs, and `flags` for the privileged-intent toggles; `redirect_uris` can be read but not written, so add them in the developer portal) |
106
106
  | `client.guilds` | `get`, `modify`, `channels`, `createChannel`, `roles`, `createRole`, `modifyRole`, `create`, `delete`, `emojis`, `member`, `members`, `membersWithRole`, `addMemberRole`, `removeMemberRole`, `welcomeScreen`, `modifyWelcomeScreen`, `onboarding`, `modifyOnboarding` |
107
107
  | `client.channels` | `modify`, `webhooks`, `createWebhook`, `createMessage`, `createInvite`, `messages`, `pin`, `deleteMessage` |
package/dist/index.d.mts CHANGED
@@ -45,6 +45,21 @@ interface DiscordUser {
45
45
  username: string;
46
46
  bot?: boolean;
47
47
  }
48
+ /** A server as `GET /users/@me/guilds` lists it: a summary, not the full guild. */
49
+ interface DiscordUserGuild {
50
+ id: string;
51
+ name: string;
52
+ /** Whether the caller (here, the bot) owns the server. */
53
+ owner: boolean;
54
+ /** The caller's permission bitfield in the server, as a decimal string. */
55
+ permissions?: string;
56
+ }
57
+ /** Page options for `users.guilds`; Discord allows a `limit` of 1–200; values outside that are clamped. */
58
+ interface ListUserGuildsInput {
59
+ limit?: number;
60
+ /** Return servers after this server id. */
61
+ after?: string;
62
+ }
48
63
  /** Guild fields `guilds.modify` can change; the numeric enums are Discord's own. */
49
64
  interface DiscordGuild {
50
65
  id: string;
@@ -359,10 +374,15 @@ declare function createDiscordBotClient(opts: DiscordBotClientOptions): {
359
374
  me: () => Promise<DiscordUser>;
360
375
  /** `GET /users/:id` — a user's name, for reports that would otherwise show a bare id. */
361
376
  get: (userId: string) => Promise<DiscordUser>;
377
+ /**
378
+ * `GET /users/@me/guilds` — one page of the servers the bot is in, each with whether it owns it. This is
379
+ * how a retry finds a server `guilds.create` already made, since that call is not idempotent.
380
+ */
381
+ guilds: (opts?: ListUserGuildsInput) => Promise<DiscordUserGuild[]>;
362
382
  };
363
383
  guilds: {
364
384
  get: (guildId: string) => Promise<DiscordGuild>;
365
- /** `POST /guilds` — a new server the bot owns. Not idempotent: look one up by name before retrying. */
385
+ /** `POST /guilds` — a new server the bot owns. Not idempotent: look one up by name (`users.guilds`) before retrying. */
366
386
  create: (body: CreateGuildInput) => Promise<DiscordGuild>;
367
387
  /** `DELETE /guilds/:id` — only the owner may; a 404 counts as done. */
368
388
  delete: (guildId: string) => Promise<void>;
@@ -611,4 +631,4 @@ declare function createDiscordClient(opts?: DiscordClientOptions): {
611
631
  };
612
632
  type DiscordClient = ReturnType<typeof createDiscordClient>;
613
633
  //#endregion
614
- export { ApplicationFlag, ChannelType, CreateChannelInput, CreateGuildInput, CreateInviteInput, CreateMessageInput, CreateRoleInput, DEFAULT_STATE_TTL_SECONDS, DiscordApplication, DiscordBotClient, DiscordBotClientOptions, DiscordChannel, DiscordChannelMessage, DiscordChannelWebhook, DiscordClient, type DiscordClientOptions, DiscordConnection, DiscordEmoji, DiscordGuild, DiscordGuildMember, DiscordInstallParams, DiscordInvite, DiscordMessage, DiscordOAuthClient, DiscordOAuthClientOptions, DiscordOAuthScope, DiscordOAuthToken, DiscordOAuthUser, DiscordOnboarding, DiscordOnboardingOption, DiscordOnboardingPrompt, DiscordPermissionOverwrite, DiscordRole, DiscordUser, type DiscordWebhookInfo, DiscordWelcomeChannel, DiscordWelcomeScreen, ListMembersInput, ModifyApplicationInput, ModifyChannelInput, ModifyGuildInput, ModifyRoleInput, ModifyWebhookInput, ModifyWelcomeScreenInput, Permission, PermissionName, createDiscordBotClient, createDiscordClient, createDiscordOAuthClient, findVerifiedConnection, parseWebhookUrl, permissionNames, permissions, signOAuthState, verifyOAuthState };
634
+ export { ApplicationFlag, ChannelType, CreateChannelInput, CreateGuildInput, CreateInviteInput, CreateMessageInput, CreateRoleInput, DEFAULT_STATE_TTL_SECONDS, DiscordApplication, DiscordBotClient, DiscordBotClientOptions, DiscordChannel, DiscordChannelMessage, DiscordChannelWebhook, DiscordClient, type DiscordClientOptions, DiscordConnection, DiscordEmoji, DiscordGuild, DiscordGuildMember, DiscordInstallParams, DiscordInvite, DiscordMessage, DiscordOAuthClient, DiscordOAuthClientOptions, DiscordOAuthScope, DiscordOAuthToken, DiscordOAuthUser, DiscordOnboarding, DiscordOnboardingOption, DiscordOnboardingPrompt, DiscordPermissionOverwrite, DiscordRole, DiscordUser, DiscordUserGuild, type DiscordWebhookInfo, DiscordWelcomeChannel, DiscordWelcomeScreen, ListMembersInput, ListUserGuildsInput, ModifyApplicationInput, ModifyChannelInput, ModifyGuildInput, ModifyRoleInput, ModifyWebhookInput, ModifyWelcomeScreenInput, Permission, PermissionName, createDiscordBotClient, createDiscordClient, createDiscordOAuthClient, findVerifiedConnection, parseWebhookUrl, permissionNames, permissions, signOAuthState, verifyOAuthState };
package/dist/index.mjs CHANGED
@@ -158,11 +158,20 @@ function createDiscordBotClient(opts) {
158
158
  /** `GET /users/@me` — the bot's own user; a cheap token check. */
159
159
  me: () => rest.request("/users/@me"),
160
160
  /** `GET /users/:id` — a user's name, for reports that would otherwise show a bare id. */
161
- get: (userId) => rest.request(`/users/${id(userId)}`)
161
+ get: (userId) => rest.request(`/users/${id(userId)}`),
162
+ /**
163
+ * `GET /users/@me/guilds` — one page of the servers the bot is in, each with whether it owns it. This is
164
+ * how a retry finds a server `guilds.create` already made, since that call is not idempotent.
165
+ */
166
+ guilds: (opts = {}) => {
167
+ const query = { limit: String(Math.min(Math.max(opts.limit ?? 200, 1), 200)) };
168
+ if (opts.after !== void 0) query.after = id(opts.after);
169
+ return rest.request("/users/@me/guilds", { query });
170
+ }
162
171
  },
163
172
  guilds: {
164
173
  get: (guildId) => rest.request(`/guilds/${id(guildId)}`),
165
- /** `POST /guilds` — a new server the bot owns. Not idempotent: look one up by name before retrying. */
174
+ /** `POST /guilds` — a new server the bot owns. Not idempotent: look one up by name (`users.guilds`) before retrying. */
166
175
  create: (body) => rest.request("/guilds", {
167
176
  method: "POST",
168
177
  body
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/discord-client",
3
- "version": "1.48.0",
3
+ "version": "1.49.0",
4
4
  "description": "A TypeScript client for the Discord webhooks API",
5
5
  "keywords": [
6
6
  "discord",
@@ -32,7 +32,7 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@theholocron/http-client": "^1.48.0"
35
+ "@theholocron/http-client": "^1.49.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@theholocron/cli": "5.0.0-alpha.79",