@theholocron/discord-client 1.47.1 → 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,8 +101,8 @@ 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 |
105
- | `client.application` | `get`, `modify` (the bot's own application: description, tags, install settings, URLs) |
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
+ | `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` |
108
108
  | `client.webhooks` | `modify` (name, avatar), `delete` |
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;
@@ -238,6 +253,18 @@ interface DiscordInstallParams {
238
253
  /** Permission bitfield the default install link asks for, as a string. */
239
254
  permissions: string;
240
255
  }
256
+ /**
257
+ * Bits of the application's `flags`. The `*Limited` ones are the portal's privileged-intent toggles for an app
258
+ * that Discord has not verified; once verified, the plain ones take over and the toggle is Discord's to change.
259
+ */
260
+ declare const ApplicationFlag: {
261
+ readonly GatewayPresence: number;
262
+ readonly GatewayPresenceLimited: number;
263
+ readonly GatewayGuildMembers: number;
264
+ readonly GatewayGuildMembersLimited: number;
265
+ readonly GatewayMessageContent: number;
266
+ readonly GatewayMessageContentLimited: number;
267
+ };
241
268
  /** The bot's own application, as `GET /applications/@me` returns it. Fields Discord leaves out are absent or null. */
242
269
  interface DiscordApplication {
243
270
  id: string;
@@ -257,6 +284,11 @@ interface DiscordApplication {
257
284
  bot_public?: boolean;
258
285
  bot_require_code_grant?: boolean;
259
286
  flags?: number;
287
+ /**
288
+ * The OAuth2 redirect URIs registered on the application. Read-only here: Discord accepts a write to this
289
+ * field and silently ignores it, so add them in the developer portal (OAuth2 → Redirects).
290
+ */
291
+ redirect_uris?: string[];
260
292
  }
261
293
  /** What `PATCH /applications/@me` takes; a field left out is left alone, and `null` clears the ones that can be cleared. */
262
294
  interface ModifyApplicationInput {
@@ -268,6 +300,11 @@ interface ModifyApplicationInput {
268
300
  terms_of_service_url?: string | null;
269
301
  privacy_policy_url?: string | null;
270
302
  interactions_endpoint_url?: string | null;
303
+ /**
304
+ * The whole flags value. Discord keeps only the bits an app may change (the `*Limited` privileged-intent
305
+ * toggles among them), so read `flags` first and send it back with your bit set or cleared.
306
+ */
307
+ flags?: number;
271
308
  }
272
309
  interface ModifyWebhookInput {
273
310
  name?: string;
@@ -337,10 +374,15 @@ declare function createDiscordBotClient(opts: DiscordBotClientOptions): {
337
374
  me: () => Promise<DiscordUser>;
338
375
  /** `GET /users/:id` — a user's name, for reports that would otherwise show a bare id. */
339
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[]>;
340
382
  };
341
383
  guilds: {
342
384
  get: (guildId: string) => Promise<DiscordGuild>;
343
- /** `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. */
344
386
  create: (body: CreateGuildInput) => Promise<DiscordGuild>;
345
387
  /** `DELETE /guilds/:id` — only the owner may; a 404 counts as done. */
346
388
  delete: (guildId: string) => Promise<void>;
@@ -589,4 +631,4 @@ declare function createDiscordClient(opts?: DiscordClientOptions): {
589
631
  };
590
632
  type DiscordClient = ReturnType<typeof createDiscordClient>;
591
633
  //#endregion
592
- export { 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
@@ -343,6 +352,18 @@ const ChannelType = {
343
352
  Announcement: 5,
344
353
  Forum: 15
345
354
  };
355
+ /**
356
+ * Bits of the application's `flags`. The `*Limited` ones are the portal's privileged-intent toggles for an app
357
+ * that Discord has not verified; once verified, the plain ones take over and the toggle is Discord's to change.
358
+ */
359
+ const ApplicationFlag = {
360
+ GatewayPresence: 4096,
361
+ GatewayPresenceLimited: 8192,
362
+ GatewayGuildMembers: 16384,
363
+ GatewayGuildMembersLimited: 32768,
364
+ GatewayMessageContent: 1 << 18,
365
+ GatewayMessageContentLimited: 1 << 19
366
+ };
346
367
  //#endregion
347
368
  //#region ../../../../../src/bot/permissions.ts
348
369
  /**
@@ -550,4 +571,4 @@ function createDiscordClient(opts = {}) {
550
571
  return { webhooks: webhooks(opts.baseUrl ?? "https://discord.com/api/v10", opts.fetch ?? globalThis.fetch) };
551
572
  }
552
573
  //#endregion
553
- export { ChannelType, DEFAULT_STATE_TTL_SECONDS, Permission, createDiscordBotClient, createDiscordClient, createDiscordOAuthClient, findVerifiedConnection, parseWebhookUrl, permissionNames, permissions, signOAuthState, verifyOAuthState };
574
+ export { ApplicationFlag, ChannelType, DEFAULT_STATE_TTL_SECONDS, Permission, createDiscordBotClient, createDiscordClient, createDiscordOAuthClient, findVerifiedConnection, parseWebhookUrl, permissionNames, permissions, signOAuthState, verifyOAuthState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/discord-client",
3
- "version": "1.47.1",
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.47.1"
35
+ "@theholocron/http-client": "^1.49.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@theholocron/cli": "5.0.0-alpha.79",