chapterjs 0.1.1 → 0.1.4

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.
Files changed (320) hide show
  1. package/dist/assets/asset.d.ts +46 -0
  2. package/dist/assets/asset.js +86 -0
  3. package/dist/assets/public.d.ts +19 -0
  4. package/dist/assets/public.js +120 -0
  5. package/dist/cache/cache.d.ts +62 -0
  6. package/dist/cache/cache.js +80 -0
  7. package/dist/cache/store.d.ts +45 -0
  8. package/dist/cache/store.js +53 -0
  9. package/dist/cli/build.d.ts +41 -0
  10. package/dist/cli/build.js +206 -0
  11. package/dist/cli/cli.js +108 -25
  12. package/dist/cli/cluster.d.ts +70 -0
  13. package/dist/cli/cluster.js +213 -0
  14. package/dist/cli/dev.d.ts +18 -1
  15. package/dist/cli/dev.js +252 -198
  16. package/dist/cli/env.d.ts +31 -0
  17. package/dist/cli/env.js +93 -0
  18. package/dist/cli/log.d.ts +13 -0
  19. package/dist/cli/log.js +17 -0
  20. package/dist/cli/node-version.d.ts +8 -0
  21. package/dist/cli/node-version.js +13 -0
  22. package/dist/cli/preflight.d.ts +36 -0
  23. package/dist/cli/preflight.js +122 -0
  24. package/dist/cli/project.d.ts +122 -0
  25. package/dist/cli/project.js +452 -0
  26. package/dist/cli/start.d.ts +25 -0
  27. package/dist/cli/start.js +225 -0
  28. package/dist/commands/autocomplete.d.ts +13 -0
  29. package/dist/commands/autocomplete.js +159 -0
  30. package/dist/commands/command.d.ts +346 -0
  31. package/dist/commands/command.js +28 -0
  32. package/dist/commands/convention.d.ts +64 -0
  33. package/dist/commands/convention.js +464 -0
  34. package/dist/commands/register.d.ts +18 -0
  35. package/dist/commands/register.js +42 -0
  36. package/dist/commands/router.d.ts +20 -0
  37. package/dist/commands/router.js +228 -0
  38. package/dist/commands/tree.d.ts +43 -0
  39. package/dist/commands/tree.js +206 -0
  40. package/dist/commands/twins.d.ts +15 -0
  41. package/dist/commands/twins.js +78 -0
  42. package/dist/components/button.d.ts +79 -0
  43. package/dist/components/button.js +108 -0
  44. package/dist/components/component.d.ts +140 -0
  45. package/dist/components/component.js +39 -0
  46. package/dist/components/convention.d.ts +35 -0
  47. package/dist/components/convention.js +339 -0
  48. package/dist/components/custom-id.d.ts +72 -0
  49. package/dist/components/custom-id.js +128 -0
  50. package/dist/components/embed.d.ts +28 -0
  51. package/dist/components/embed.js +11 -0
  52. package/dist/components/file.d.ts +30 -0
  53. package/dist/components/file.js +52 -0
  54. package/dist/components/instance.d.ts +100 -0
  55. package/dist/components/instance.js +86 -0
  56. package/dist/components/layout.d.ts +103 -0
  57. package/dist/components/layout.js +279 -0
  58. package/dist/components/modal.d.ts +244 -0
  59. package/dist/components/modal.js +399 -0
  60. package/dist/components/options.d.ts +41 -0
  61. package/dist/components/options.js +101 -0
  62. package/dist/components/render.d.ts +12 -0
  63. package/dist/components/render.js +58 -0
  64. package/dist/components/router.d.ts +18 -0
  65. package/dist/components/router.js +256 -0
  66. package/dist/components/select.d.ts +144 -0
  67. package/dist/components/select.js +179 -0
  68. package/dist/core/bot.d.ts +99 -0
  69. package/dist/core/bot.js +174 -0
  70. package/dist/core/memory.d.ts +66 -0
  71. package/dist/core/memory.js +115 -0
  72. package/dist/discord/api.d.ts +112 -0
  73. package/dist/discord/api.js +115 -0
  74. package/dist/discord/cdn.d.ts +67 -0
  75. package/dist/discord/cdn.js +100 -0
  76. package/dist/discord/codes.d.ts +171 -0
  77. package/dist/discord/codes.js +421 -0
  78. package/dist/discord/endpoint.d.ts +56 -0
  79. package/dist/discord/endpoint.js +53 -0
  80. package/dist/discord/endpoints.d.ts +1529 -0
  81. package/dist/discord/endpoints.js +1139 -0
  82. package/dist/discord/formatting.d.ts +67 -0
  83. package/dist/discord/formatting.js +87 -0
  84. package/dist/discord/index.d.ts +10 -0
  85. package/dist/discord/index.js +13 -0
  86. package/dist/discord/intents.d.ts +48 -0
  87. package/dist/discord/intents.js +128 -0
  88. package/dist/discord/permissions.d.ts +94 -0
  89. package/dist/discord/permissions.js +185 -0
  90. package/dist/discord/snowflake.d.ts +21 -0
  91. package/dist/discord/snowflake.js +36 -0
  92. package/dist/discord/types/application-command.d.ts +332 -0
  93. package/dist/discord/types/application-command.js +48 -0
  94. package/dist/discord/types/application-role-connection-metadata.d.ts +42 -0
  95. package/dist/discord/types/application-role-connection-metadata.js +22 -0
  96. package/dist/discord/types/application.d.ts +208 -0
  97. package/dist/discord/types/application.js +48 -0
  98. package/dist/discord/types/audit-log.d.ts +255 -0
  99. package/dist/discord/types/audit-log.js +144 -0
  100. package/dist/discord/types/auto-moderation.d.ts +167 -0
  101. package/dist/discord/types/auto-moderation.js +52 -0
  102. package/dist/discord/types/channel.d.ts +557 -0
  103. package/dist/discord/types/channel.js +88 -0
  104. package/dist/discord/types/common.d.ts +54 -0
  105. package/dist/discord/types/common.js +38 -0
  106. package/dist/discord/types/component.d.ts +775 -0
  107. package/dist/discord/types/component.js +76 -0
  108. package/dist/discord/types/emoji.d.ts +74 -0
  109. package/dist/discord/types/emoji.js +1 -0
  110. package/dist/discord/types/entitlement.d.ts +84 -0
  111. package/dist/discord/types/entitlement.js +22 -0
  112. package/dist/discord/types/gateway-events.d.ts +1148 -0
  113. package/dist/discord/types/gateway-events.js +54 -0
  114. package/dist/discord/types/gateway.d.ts +38 -0
  115. package/dist/discord/types/gateway.js +1 -0
  116. package/dist/discord/types/guild-scheduled-event.d.ts +257 -0
  117. package/dist/discord/types/guild-scheduled-event.js +68 -0
  118. package/dist/discord/types/guild-template.d.ts +51 -0
  119. package/dist/discord/types/guild-template.js +1 -0
  120. package/dist/discord/types/guild.d.ts +910 -0
  121. package/dist/discord/types/guild.js +153 -0
  122. package/dist/discord/types/index.d.ts +31 -0
  123. package/dist/discord/types/index.js +31 -0
  124. package/dist/discord/types/interaction.d.ts +321 -0
  125. package/dist/discord/types/interaction.js +47 -0
  126. package/dist/discord/types/invite.d.ts +158 -0
  127. package/dist/discord/types/invite.js +39 -0
  128. package/dist/discord/types/message.d.ts +834 -0
  129. package/dist/discord/types/message.js +159 -0
  130. package/dist/discord/types/oauth2.d.ts +22 -0
  131. package/dist/discord/types/oauth2.js +1 -0
  132. package/dist/discord/types/permissions.d.ts +183 -0
  133. package/dist/discord/types/permissions.js +118 -0
  134. package/dist/discord/types/poll.d.ts +106 -0
  135. package/dist/discord/types/poll.js +8 -0
  136. package/dist/discord/types/sku.d.ts +47 -0
  137. package/dist/discord/types/sku.js +26 -0
  138. package/dist/discord/types/soundboard.d.ts +71 -0
  139. package/dist/discord/types/soundboard.js +1 -0
  140. package/dist/discord/types/stage-instance.d.ts +58 -0
  141. package/dist/discord/types/stage-instance.js +10 -0
  142. package/dist/discord/types/sticker.d.ts +115 -0
  143. package/dist/discord/types/sticker.js +20 -0
  144. package/dist/discord/types/subscription.d.ts +54 -0
  145. package/dist/discord/types/subscription.js +12 -0
  146. package/dist/discord/types/team.d.ts +55 -0
  147. package/dist/discord/types/team.js +21 -0
  148. package/dist/discord/types/user.d.ts +273 -0
  149. package/dist/discord/types/user.js +83 -0
  150. package/dist/discord/types/voice.d.ts +72 -0
  151. package/dist/discord/types/voice.js +1 -0
  152. package/dist/discord/types/webhook.d.ts +184 -0
  153. package/dist/discord/types/webhook.js +12 -0
  154. package/dist/events/convention.d.ts +25 -0
  155. package/dist/events/convention.js +97 -0
  156. package/dist/events/event.d.ts +8 -0
  157. package/dist/events/event.js +20 -0
  158. package/dist/events/registry.d.ts +706 -0
  159. package/dist/events/registry.js +839 -0
  160. package/dist/events/router.d.ts +45 -0
  161. package/dist/events/router.js +133 -0
  162. package/dist/events/types.d.ts +7 -0
  163. package/dist/events/types.js +48 -0
  164. package/dist/gateway/errors.d.ts +18 -0
  165. package/dist/gateway/errors.js +47 -0
  166. package/dist/gateway/gateway.d.ts +64 -0
  167. package/dist/gateway/gateway.js +117 -0
  168. package/dist/gateway/identify-queue.d.ts +25 -0
  169. package/dist/gateway/identify-queue.js +29 -0
  170. package/dist/gateway/shard.d.ts +94 -0
  171. package/dist/gateway/shard.js +414 -0
  172. package/dist/gateway/state.d.ts +11 -0
  173. package/dist/gateway/state.js +184 -0
  174. package/dist/index.d.ts +55 -18
  175. package/dist/index.js +38 -12
  176. package/dist/interactions/cooldown.d.ts +33 -0
  177. package/dist/interactions/cooldown.js +74 -0
  178. package/dist/interactions/dispatch.d.ts +91 -0
  179. package/dist/interactions/dispatch.js +110 -0
  180. package/dist/loader/generated.d.ts +37 -0
  181. package/dist/loader/generated.js +114 -0
  182. package/dist/loader/hot.d.ts +13 -0
  183. package/dist/loader/hot.js +85 -0
  184. package/dist/loader/loader.d.ts +72 -0
  185. package/dist/loader/loader.js +135 -0
  186. package/dist/loader/locate.d.ts +10 -0
  187. package/dist/loader/locate.js +36 -0
  188. package/dist/loader/watch.d.ts +17 -0
  189. package/dist/loader/watch.js +66 -0
  190. package/dist/main.d.ts +3 -0
  191. package/dist/main.js +6 -0
  192. package/dist/messages/commands.d.ts +23 -0
  193. package/dist/messages/commands.js +123 -0
  194. package/dist/messages/convention.d.ts +89 -0
  195. package/dist/messages/convention.js +347 -0
  196. package/dist/messages/messages.d.ts +219 -0
  197. package/dist/messages/messages.js +30 -0
  198. package/dist/messages/phrases.d.ts +23 -0
  199. package/dist/messages/phrases.js +44 -0
  200. package/dist/messages/translate.d.ts +100 -0
  201. package/dist/messages/translate.js +249 -0
  202. package/dist/presence/convention.d.ts +26 -0
  203. package/dist/presence/convention.js +133 -0
  204. package/dist/presence/presence.d.ts +57 -0
  205. package/dist/presence/presence.js +27 -0
  206. package/dist/rest/errors.d.ts +55 -0
  207. package/dist/rest/errors.js +92 -0
  208. package/dist/rest/rate-limiter.d.ts +46 -0
  209. package/dist/rest/rate-limiter.js +153 -0
  210. package/dist/rest/rest.d.ts +63 -0
  211. package/dist/rest/rest.js +194 -0
  212. package/dist/structures/base.d.ts +48 -0
  213. package/dist/structures/base.js +84 -0
  214. package/dist/structures/channel.d.ts +380 -0
  215. package/dist/structures/channel.js +627 -0
  216. package/dist/structures/context.d.ts +30 -0
  217. package/dist/structures/context.js +7 -0
  218. package/dist/structures/emoji.d.ts +46 -0
  219. package/dist/structures/emoji.js +65 -0
  220. package/dist/structures/entities.d.ts +62 -0
  221. package/dist/structures/entities.js +226 -0
  222. package/dist/structures/guild.d.ts +348 -0
  223. package/dist/structures/guild.js +466 -0
  224. package/dist/structures/interaction.d.ts +197 -0
  225. package/dist/structures/interaction.js +396 -0
  226. package/dist/structures/invite.d.ts +38 -0
  227. package/dist/structures/invite.js +57 -0
  228. package/dist/structures/known.d.ts +28 -0
  229. package/dist/structures/known.js +58 -0
  230. package/dist/structures/member.d.ts +140 -0
  231. package/dist/structures/member.js +260 -0
  232. package/dist/structures/message.d.ts +197 -0
  233. package/dist/structures/message.js +268 -0
  234. package/dist/structures/payload.d.ts +91 -0
  235. package/dist/structures/payload.js +184 -0
  236. package/dist/structures/role.d.ts +69 -0
  237. package/dist/structures/role.js +112 -0
  238. package/dist/structures/user.d.ts +59 -0
  239. package/dist/structures/user.js +94 -0
  240. package/dist/structures/webhook.d.ts +46 -0
  241. package/dist/structures/webhook.js +79 -0
  242. package/dist/tasks/convention.d.ts +26 -0
  243. package/dist/tasks/convention.js +78 -0
  244. package/dist/tasks/schedule.d.ts +54 -0
  245. package/dist/tasks/schedule.js +236 -0
  246. package/dist/tasks/scheduler.d.ts +33 -0
  247. package/dist/tasks/scheduler.js +107 -0
  248. package/dist/tasks/task.d.ts +76 -0
  249. package/dist/tasks/task.js +28 -0
  250. package/dist/util/case.d.ts +13 -0
  251. package/dist/util/case.js +54 -0
  252. package/dist/util/duration.d.ts +8 -0
  253. package/dist/util/duration.js +29 -0
  254. package/dist/util/websocket.d.ts +9 -0
  255. package/dist/util/websocket.js +31 -0
  256. package/dist/voice/connection.d.ts +90 -0
  257. package/dist/voice/connection.js +494 -0
  258. package/dist/voice/dave.d.ts +109 -0
  259. package/dist/voice/dave.js +245 -0
  260. package/dist/voice/opus.d.ts +19 -0
  261. package/dist/voice/opus.js +273 -0
  262. package/dist/voice/session.d.ts +55 -0
  263. package/dist/voice/session.js +405 -0
  264. package/dist/voice/source.d.ts +22 -0
  265. package/dist/voice/source.js +195 -0
  266. package/dist/voice/transport.d.ts +43 -0
  267. package/dist/voice/transport.js +140 -0
  268. package/dist/voice/usage.d.ts +4 -0
  269. package/dist/voice/usage.js +33 -0
  270. package/package.json +26 -7
  271. package/vendor/dave/LICENSE +231 -0
  272. package/vendor/dave/libdave.d.mts +99 -0
  273. package/vendor/dave/libdave.mjs +2 -0
  274. package/vendor/dave/libdave.wasm +0 -0
  275. package/dist/components.d.ts +0 -97
  276. package/dist/components.js +0 -260
  277. package/dist/context.d.ts +0 -72
  278. package/dist/context.js +0 -273
  279. package/dist/discord/client.d.ts +0 -35
  280. package/dist/discord/client.js +0 -66
  281. package/dist/discord/constants.d.ts +0 -49
  282. package/dist/discord/constants.js +0 -61
  283. package/dist/discord/events.d.ts +0 -129
  284. package/dist/discord/events.js +0 -102
  285. package/dist/discord/gateway.d.ts +0 -61
  286. package/dist/discord/gateway.js +0 -320
  287. package/dist/discord/payloads.d.ts +0 -275
  288. package/dist/discord/payloads.js +0 -3
  289. package/dist/discord/presence.d.ts +0 -42
  290. package/dist/discord/presence.js +0 -51
  291. package/dist/discord/rest.d.ts +0 -49
  292. package/dist/discord/rest.js +0 -271
  293. package/dist/discord/types.d.ts +0 -334
  294. package/dist/discord/types.js +0 -4
  295. package/dist/events.d.ts +0 -94
  296. package/dist/events.js +0 -255
  297. package/dist/presence.d.ts +0 -92
  298. package/dist/presence.js +0 -250
  299. package/dist/structures/Channel.d.ts +0 -110
  300. package/dist/structures/Channel.js +0 -171
  301. package/dist/structures/Guild.d.ts +0 -70
  302. package/dist/structures/Guild.js +0 -105
  303. package/dist/structures/Interaction.d.ts +0 -113
  304. package/dist/structures/Interaction.js +0 -274
  305. package/dist/structures/Member.d.ts +0 -70
  306. package/dist/structures/Member.js +0 -124
  307. package/dist/structures/Message.d.ts +0 -87
  308. package/dist/structures/Message.js +0 -182
  309. package/dist/structures/Reaction.d.ts +0 -38
  310. package/dist/structures/Reaction.js +0 -64
  311. package/dist/structures/Role.d.ts +0 -43
  312. package/dist/structures/Role.js +0 -77
  313. package/dist/structures/User.d.ts +0 -41
  314. package/dist/structures/User.js +0 -79
  315. package/dist/structures/utils.d.ts +0 -72
  316. package/dist/structures/utils.js +0 -59
  317. package/dist/utils/errors.d.ts +0 -5
  318. package/dist/utils/errors.js +0 -28
  319. package/dist/utils/modules.d.ts +0 -39
  320. package/dist/utils/modules.js +0 -156
@@ -1,70 +0,0 @@
1
- import type { Client } from '../discord/client.js';
2
- import type { APIGuild, Snowflake } from '../discord/types.js';
3
- import { Channel } from './Channel.js';
4
- import { Member } from './Member.js';
5
- import { Role } from './Role.js';
6
- import { type ImageOptions } from './utils.js';
7
- export interface BanOptions {
8
- /** Deletes the user's messages from the last seconds, up to 604800 (7 days). */
9
- deleteMessageSeconds?: number;
10
- reason?: string;
11
- }
12
- /**
13
- * A server. Events often only send its id: fields Discord didn't send are
14
- * undefined, `fetch()` returns the full guild.
15
- * https://docs.discord.com/developers/resources/guild#guild-object
16
- */
17
- export declare class Guild {
18
- readonly client: Client;
19
- readonly raw: Partial<APIGuild> & {
20
- id: Snowflake;
21
- unavailable?: boolean;
22
- member_count?: number;
23
- };
24
- readonly id: Snowflake;
25
- readonly name: string | undefined;
26
- readonly icon: string | null | undefined;
27
- readonly ownerId: Snowflake | undefined;
28
- readonly description: string | null | undefined;
29
- /** Sent in GUILD_CREATE only. */
30
- readonly memberCount: number | undefined;
31
- /** True during an outage, when Discord couldn't send the guild's data. */
32
- readonly unavailable: boolean;
33
- constructor(client: Client, raw: Partial<APIGuild> & {
34
- id: Snowflake;
35
- unavailable?: boolean;
36
- member_count?: number;
37
- });
38
- get createdAt(): Date;
39
- iconURL(options?: ImageOptions): string | null;
40
- /** https://docs.discord.com/developers/resources/guild#get-guild */
41
- fetch(): Promise<Guild>;
42
- /** https://docs.discord.com/developers/resources/guild#get-guild-member */
43
- fetchMember(userId: Snowflake): Promise<Member>;
44
- /**
45
- * Members sorted by id, 1000 per call by default (Discord's default is 1):
46
- * pass the last id as `after` for the next page. Needs the GuildMembers intent.
47
- * https://docs.discord.com/developers/resources/guild#list-guild-members
48
- */
49
- fetchMembers(options?: {
50
- limit?: number;
51
- after?: Snowflake;
52
- }): Promise<Member[]>;
53
- /** https://docs.discord.com/developers/resources/guild#get-guild-channels */
54
- fetchChannels(): Promise<Channel[]>;
55
- /** https://docs.discord.com/developers/resources/guild#get-guild-roles */
56
- fetchRoles(): Promise<Role[]>;
57
- /**
58
- * Creates a role with fields of the documented JSON params (snake_case).
59
- * https://docs.discord.com/developers/resources/guild#create-guild-role
60
- */
61
- createRole(data?: Record<string, unknown>, reason?: string): Promise<Role>;
62
- /** https://docs.discord.com/developers/resources/guild#create-guild-ban */
63
- ban(userId: Snowflake, options?: BanOptions): Promise<void>;
64
- /** https://docs.discord.com/developers/resources/guild#remove-guild-ban */
65
- unban(userId: Snowflake, reason?: string): Promise<void>;
66
- /** https://docs.discord.com/developers/resources/guild#remove-guild-member */
67
- kick(userId: Snowflake, reason?: string): Promise<void>;
68
- /** Makes the bot leave the server. https://docs.discord.com/developers/resources/user#leave-guild */
69
- leave(): Promise<void>;
70
- }
@@ -1,105 +0,0 @@
1
- import { Channel } from './Channel.js';
2
- import { Member } from './Member.js';
3
- import { Role } from './Role.js';
4
- import { cdnUrl, snowflakeDate } from './utils.js';
5
- /**
6
- * A server. Events often only send its id: fields Discord didn't send are
7
- * undefined, `fetch()` returns the full guild.
8
- * https://docs.discord.com/developers/resources/guild#guild-object
9
- */
10
- export class Guild {
11
- client;
12
- raw;
13
- id;
14
- name;
15
- icon;
16
- ownerId;
17
- description;
18
- /** Sent in GUILD_CREATE only. */
19
- memberCount;
20
- /** True during an outage, when Discord couldn't send the guild's data. */
21
- unavailable;
22
- constructor(client, raw) {
23
- this.client = client;
24
- this.raw = raw;
25
- this.id = raw.id;
26
- this.name = raw.name;
27
- this.icon = raw.icon;
28
- this.ownerId = raw.owner_id;
29
- this.description = raw.description;
30
- this.memberCount = raw.member_count;
31
- this.unavailable = raw.unavailable ?? false;
32
- }
33
- get createdAt() {
34
- return snowflakeDate(this.id);
35
- }
36
- iconURL(options) {
37
- return this.icon ? cdnUrl(`icons/${this.id}`, this.icon, options) : null;
38
- }
39
- /** https://docs.discord.com/developers/resources/guild#get-guild */
40
- async fetch() {
41
- return new Guild(this.client, await this.client.rest.get(`/guilds/${this.id}`));
42
- }
43
- /** https://docs.discord.com/developers/resources/guild#get-guild-member */
44
- async fetchMember(userId) {
45
- const member = await this.client.rest.get(`/guilds/${this.id}/members/${userId}`);
46
- return new Member(this.client, this.id, member);
47
- }
48
- /**
49
- * Members sorted by id, 1000 per call by default (Discord's default is 1):
50
- * pass the last id as `after` for the next page. Needs the GuildMembers intent.
51
- * https://docs.discord.com/developers/resources/guild#list-guild-members
52
- */
53
- async fetchMembers(options = {}) {
54
- const members = await this.client.rest.get(`/guilds/${this.id}/members`, {
55
- query: { limit: 1000, ...options },
56
- });
57
- return members.map(member => new Member(this.client, this.id, member));
58
- }
59
- /** https://docs.discord.com/developers/resources/guild#get-guild-channels */
60
- async fetchChannels() {
61
- const channels = await this.client.rest.get(`/guilds/${this.id}/channels`);
62
- return channels.map(channel => new Channel(this.client, { guild_id: this.id, ...channel }));
63
- }
64
- /** https://docs.discord.com/developers/resources/guild#get-guild-roles */
65
- async fetchRoles() {
66
- const roles = await this.client.rest.get(`/guilds/${this.id}/roles`);
67
- return roles.map(role => new Role(this.client, this.id, role));
68
- }
69
- /**
70
- * Creates a role with fields of the documented JSON params (snake_case).
71
- * https://docs.discord.com/developers/resources/guild#create-guild-role
72
- */
73
- async createRole(data = {}, reason) {
74
- const role = await this.client.rest.post(`/guilds/${this.id}/roles`, {
75
- body: data,
76
- reason,
77
- });
78
- return new Role(this.client, this.id, role);
79
- }
80
- /** https://docs.discord.com/developers/resources/guild#create-guild-ban */
81
- async ban(userId, options = {}) {
82
- await this.client.rest.put(`/guilds/${this.id}/bans/${userId}`, {
83
- body: options.deleteMessageSeconds !== undefined
84
- ? { delete_message_seconds: options.deleteMessageSeconds }
85
- : {},
86
- reason: options.reason,
87
- });
88
- }
89
- /** https://docs.discord.com/developers/resources/guild#remove-guild-ban */
90
- async unban(userId, reason) {
91
- await this.client.rest.delete(`/guilds/${this.id}/bans/${userId}`, {
92
- reason,
93
- });
94
- }
95
- /** https://docs.discord.com/developers/resources/guild#remove-guild-member */
96
- async kick(userId, reason) {
97
- await this.client.rest.delete(`/guilds/${this.id}/members/${userId}`, {
98
- reason,
99
- });
100
- }
101
- /** Makes the bot leave the server. https://docs.discord.com/developers/resources/user#leave-guild */
102
- async leave() {
103
- await this.client.rest.delete(`/users/@me/guilds/${this.id}`);
104
- }
105
- }
@@ -1,113 +0,0 @@
1
- import { type Client } from '../discord/client.js';
2
- import type { APIInteraction, GatewayObject, Snowflake } from '../discord/types.js';
3
- import { Channel } from './Channel.js';
4
- import { Guild } from './Guild.js';
5
- import { Member } from './Member.js';
6
- import { Message } from './Message.js';
7
- import { User } from './User.js';
8
- import { type MessageOptions } from './utils.js';
9
- export declare const InteractionType: {
10
- readonly Ping: 1;
11
- readonly ApplicationCommand: 2;
12
- readonly MessageComponent: 3;
13
- readonly ApplicationCommandAutocomplete: 4;
14
- readonly ModalSubmit: 5;
15
- };
16
- export type InteractionReplyOptions = MessageOptions & {
17
- /** Only visible to the user who triggered the interaction. */
18
- ephemeral?: boolean;
19
- };
20
- export interface AutocompleteChoice {
21
- /** 1 to 100 characters. */
22
- name: string;
23
- value: string | number;
24
- }
25
- export interface ModalOptions {
26
- customId: string;
27
- /** Up to 45 characters. */
28
- title: string;
29
- /** 1 to 5 components, https://docs.discord.com/developers/components/reference */
30
- components: object[];
31
- }
32
- /**
33
- * A slash command, button, select menu, modal submit or autocomplete. Must be
34
- * answered within 3 seconds (`reply`, `defer`, `update`, `respond`, `showModal`).
35
- * https://docs.discord.com/developers/interactions/receiving-and-responding
36
- */
37
- export declare class Interaction {
38
- #private;
39
- readonly client: Client;
40
- readonly raw: APIInteraction;
41
- readonly id: Snowflake;
42
- /** See `InteractionType`. */
43
- readonly type: number;
44
- readonly applicationId: Snowflake;
45
- readonly token: string;
46
- readonly guildId: Snowflake | null;
47
- readonly channelId: Snowflake | null;
48
- /** Who triggered it. */
49
- readonly user: User;
50
- /** Who triggered it, as a server member. Null in DMs. */
51
- readonly member: Member | null;
52
- /** Message of the clicked component. */
53
- readonly message: Message | null;
54
- readonly locale: string | null;
55
- readonly guildLocale: string | null;
56
- /** Permissions of the bot where the interaction happened. */
57
- readonly appPermissions: string;
58
- /** Type-specific data, https://docs.discord.com/developers/interactions/receiving-and-responding#interaction-object-interaction-data */
59
- readonly data: GatewayObject;
60
- /** True once a first response (reply, defer…) was sent. */
61
- acknowledged: boolean;
62
- /** True when acknowledged with `defer`: answer with `editReply`. */
63
- deferred: boolean;
64
- constructor(client: Client, raw: APIInteraction);
65
- get channel(): Channel | null;
66
- get guild(): Guild | null;
67
- isCommand(): boolean;
68
- isAutocomplete(): boolean;
69
- /** Button or select menu. */
70
- isComponent(): boolean;
71
- isModalSubmit(): boolean;
72
- /** Name of the command, for commands and autocompletes. */
73
- get commandName(): string | null;
74
- /** `custom_id` of the button, select menu or modal. */
75
- get customId(): string | null;
76
- /** Values picked in a select menu. */
77
- get values(): string[];
78
- get subcommandGroup(): string | null;
79
- get subcommand(): string | null;
80
- /**
81
- * Value of a command option, looked up inside subcommands. Users, channels
82
- * and roles are ids: their objects are in `data.resolved`.
83
- */
84
- option<T extends string | number | boolean = string>(name: string): T | undefined;
85
- /** Option being typed, for autocompletes. */
86
- get focusedOption(): {
87
- name: string;
88
- value: string;
89
- } | null;
90
- /** Value of a modal field by its `custom_id`. */
91
- field(customId: string): string | undefined;
92
- /** What the interaction is, for messages: `command /ping`, `button src/components/sayHi`… */
93
- describe(): string;
94
- /** Answers with a message. */
95
- reply(options: InteractionReplyOptions): Promise<void>;
96
- /** Shows "Bot is thinking…": answer within 15 minutes with `editReply`. */
97
- defer(options?: {
98
- ephemeral?: boolean;
99
- }): Promise<void>;
100
- /** Components only: acknowledges without loading state, edit the message later. */
101
- deferUpdate(): Promise<void>;
102
- /** Components only: edits the message the component is attached to. */
103
- update(options: MessageOptions): Promise<void>;
104
- /** Autocompletes only: up to 25 suggestions. */
105
- respond(choices: AutocompleteChoice[]): Promise<void>;
106
- /** Opens a modal. Not available for modal submits. */
107
- showModal(modal: ModalOptions): Promise<void>;
108
- /** Edits the first response, e.g. after `defer`. */
109
- editReply(options: MessageOptions): Promise<Message>;
110
- deleteReply(): Promise<void>;
111
- /** Sends another message, within 15 minutes of the interaction. */
112
- followUp(options: InteractionReplyOptions): Promise<Message>;
113
- }
@@ -1,274 +0,0 @@
1
- import { emitWarning } from '../discord/client.js';
2
- import { Channel } from './Channel.js';
3
- import { Guild } from './Guild.js';
4
- import { Member } from './Member.js';
5
- import { Message } from './Message.js';
6
- import { User } from './User.js';
7
- import { toMessageBody } from './utils.js';
8
- // https://docs.discord.com/developers/interactions/receiving-and-responding#interaction-object-interaction-type
9
- export const InteractionType = {
10
- Ping: 1,
11
- ApplicationCommand: 2,
12
- MessageComponent: 3,
13
- ApplicationCommandAutocomplete: 4,
14
- ModalSubmit: 5,
15
- };
16
- // https://docs.discord.com/developers/interactions/receiving-and-responding#interaction-response-object-interaction-callback-type
17
- const CallbackType = {
18
- ChannelMessageWithSource: 4,
19
- DeferredChannelMessageWithSource: 5,
20
- DeferredUpdateMessage: 6,
21
- UpdateMessage: 7,
22
- ApplicationCommandAutocompleteResult: 8,
23
- Modal: 9,
24
- };
25
- /** https://docs.discord.com/developers/resources/message#message-object-message-flags */
26
- const EPHEMERAL = 1 << 6;
27
- /** Discord invalidates the interaction when no response is sent in time. */
28
- const RESPONSE_DEADLINE = 3_000;
29
- /** https://docs.discord.com/developers/interactions/application-commands#application-command-object-application-command-option-type */
30
- const SUB_COMMAND = 1;
31
- const SUB_COMMAND_GROUP = 2;
32
- /**
33
- * A slash command, button, select menu, modal submit or autocomplete. Must be
34
- * answered within 3 seconds (`reply`, `defer`, `update`, `respond`, `showModal`).
35
- * https://docs.discord.com/developers/interactions/receiving-and-responding
36
- */
37
- export class Interaction {
38
- client;
39
- raw;
40
- id;
41
- /** See `InteractionType`. */
42
- type;
43
- applicationId;
44
- token;
45
- guildId;
46
- channelId;
47
- /** Who triggered it. */
48
- user;
49
- /** Who triggered it, as a server member. Null in DMs. */
50
- member;
51
- /** Message of the clicked component. */
52
- message;
53
- locale;
54
- guildLocale;
55
- /** Permissions of the bot where the interaction happened. */
56
- appPermissions;
57
- /** Type-specific data, https://docs.discord.com/developers/interactions/receiving-and-responding#interaction-object-interaction-data */
58
- data;
59
- /** True once a first response (reply, defer…) was sent. */
60
- acknowledged = false;
61
- /** True when acknowledged with `defer`: answer with `editReply`. */
62
- deferred = false;
63
- constructor(client, raw) {
64
- this.client = client;
65
- this.raw = raw;
66
- this.id = raw.id;
67
- this.type = raw.type;
68
- this.applicationId = raw.application_id;
69
- this.token = raw.token;
70
- this.guildId = raw.guild_id ?? null;
71
- this.channelId = raw.channel_id ?? raw.channel?.id ?? null;
72
- this.member =
73
- raw.member?.user && this.guildId
74
- ? new Member(client, this.guildId, {
75
- ...raw.member,
76
- user: raw.member.user,
77
- })
78
- : null;
79
- this.user = this.member?.user ?? new User(client, raw.user);
80
- this.message = raw.message
81
- ? new Message(client, { guild_id: raw.guild_id, ...raw.message })
82
- : null;
83
- this.locale = raw.locale ?? null;
84
- this.guildLocale = raw.guild_locale ?? null;
85
- this.appPermissions = raw.app_permissions;
86
- this.data = raw.data ?? {};
87
- if (this.type !== InteractionType.Ping) {
88
- setTimeout(() => {
89
- if (!this.acknowledged) {
90
- emitWarning(client, `The ${this.describe()} was not answered within 3 seconds, so Discord showed an error to the user. ` +
91
- 'Answer with interaction.reply(), or call interaction.defer() first when your code needs more time.');
92
- }
93
- }, RESPONSE_DEADLINE).unref();
94
- }
95
- }
96
- get channel() {
97
- if (!this.channelId)
98
- return null;
99
- return new Channel(this.client, {
100
- ...this.raw.channel,
101
- id: this.channelId,
102
- ...(this.guildId && { guild_id: this.guildId }),
103
- });
104
- }
105
- get guild() {
106
- return this.guildId ? new Guild(this.client, { id: this.guildId }) : null;
107
- }
108
- isCommand() {
109
- return this.type === InteractionType.ApplicationCommand;
110
- }
111
- isAutocomplete() {
112
- return this.type === InteractionType.ApplicationCommandAutocomplete;
113
- }
114
- /** Button or select menu. */
115
- isComponent() {
116
- return this.type === InteractionType.MessageComponent;
117
- }
118
- isModalSubmit() {
119
- return this.type === InteractionType.ModalSubmit;
120
- }
121
- /** Name of the command, for commands and autocompletes. */
122
- get commandName() {
123
- return this.data.name ?? null;
124
- }
125
- /** `custom_id` of the button, select menu or modal. */
126
- get customId() {
127
- return this.data.custom_id ?? null;
128
- }
129
- /** Values picked in a select menu. */
130
- get values() {
131
- return this.data.values ?? [];
132
- }
133
- get subcommandGroup() {
134
- const group = this.data.options?.find(option => option.type === SUB_COMMAND_GROUP);
135
- return group?.name ?? null;
136
- }
137
- get subcommand() {
138
- return this.#leafOptions().subcommand;
139
- }
140
- /**
141
- * Value of a command option, looked up inside subcommands. Users, channels
142
- * and roles are ids: their objects are in `data.resolved`.
143
- */
144
- option(name) {
145
- return this.#leafOptions().options.find(option => option.name === name)
146
- ?.value;
147
- }
148
- /** Option being typed, for autocompletes. */
149
- get focusedOption() {
150
- const focused = this.#leafOptions().options.find(option => option.focused);
151
- return focused
152
- ? { name: focused.name, value: String(focused.value ?? '') }
153
- : null;
154
- }
155
- /** Value of a modal field by its `custom_id`. */
156
- field(customId) {
157
- const find = (components = []) => {
158
- for (const component of components) {
159
- if (component.custom_id === customId && 'value' in component)
160
- return component.value;
161
- const nested = find(component.components ?? (component.component && [component.component]));
162
- if (nested !== undefined)
163
- return nested;
164
- }
165
- return undefined;
166
- };
167
- return find(this.data.components);
168
- }
169
- #leafOptions() {
170
- let options = (this.data.options ?? []);
171
- let subcommand = null;
172
- for (;;) {
173
- const nested = options.find(option => option.type === SUB_COMMAND || option.type === SUB_COMMAND_GROUP);
174
- if (!nested)
175
- return { subcommand, options };
176
- if (nested.type === SUB_COMMAND)
177
- subcommand = nested.name;
178
- options = nested.options ?? [];
179
- }
180
- }
181
- /** What the interaction is, for messages: `command /ping`, `button src/components/sayHi`… */
182
- describe() {
183
- if (this.commandName)
184
- return `command /${this.commandName}`;
185
- // Components of src/components/ (see components.ts)
186
- if (this.customId?.startsWith('cjs:')) {
187
- return `button src/components/${this.customId.slice(4).split('|')[0]}`;
188
- }
189
- if (this.customId)
190
- return `component "${this.customId}"`;
191
- return `interaction ${this.id}`;
192
- }
193
- // https://docs.discord.com/developers/interactions/receiving-and-responding#create-interaction-response
194
- async #callback(type, data, files) {
195
- if (this.acknowledged) {
196
- throw new Error(`The ${this.describe()} was already answered, and Discord accepts only one answer: ` +
197
- 'use interaction.editReply() to change it, or interaction.followUp() to send another message.');
198
- }
199
- this.acknowledged = true;
200
- await this.client.rest.post(`/interactions/${this.id}/${this.token}/callback`, {
201
- body: { type, ...(data !== undefined && { data }) },
202
- files,
203
- });
204
- }
205
- /** Answers with a message. */
206
- reply(options) {
207
- const { body, files } = toCallbackMessage(options);
208
- return this.#callback(CallbackType.ChannelMessageWithSource, body, files);
209
- }
210
- /** Shows "Bot is thinking…": answer within 15 minutes with `editReply`. */
211
- async defer(options = {}) {
212
- await this.#callback(CallbackType.DeferredChannelMessageWithSource, options.ephemeral ? { flags: EPHEMERAL } : undefined);
213
- this.deferred = true;
214
- }
215
- /** Components only: acknowledges without loading state, edit the message later. */
216
- async deferUpdate() {
217
- await this.#callback(CallbackType.DeferredUpdateMessage);
218
- this.deferred = true;
219
- }
220
- /** Components only: edits the message the component is attached to. */
221
- update(options) {
222
- const { body, files } = toMessageBody(options);
223
- return this.#callback(CallbackType.UpdateMessage, body, files);
224
- }
225
- /** Autocompletes only: up to 25 suggestions. */
226
- respond(choices) {
227
- return this.#callback(CallbackType.ApplicationCommandAutocompleteResult, {
228
- choices,
229
- });
230
- }
231
- /** Opens a modal. Not available for modal submits. */
232
- showModal(modal) {
233
- return this.#callback(CallbackType.Modal, {
234
- custom_id: modal.customId,
235
- title: modal.title,
236
- components: modal.components,
237
- });
238
- }
239
- #webhookPath(suffix = '') {
240
- return `/webhooks/${this.applicationId}/${this.token}${suffix}`;
241
- }
242
- #wrap(message) {
243
- return new Message(this.client, {
244
- guild_id: this.guildId ?? undefined,
245
- ...message,
246
- });
247
- }
248
- /** Edits the first response, e.g. after `defer`. */
249
- async editReply(options) {
250
- const { body, files } = toMessageBody(options);
251
- return this.#wrap(await this.client.rest.patch(this.#webhookPath('/messages/@original'), {
252
- body,
253
- files,
254
- }));
255
- }
256
- async deleteReply() {
257
- await this.client.rest.delete(this.#webhookPath('/messages/@original'));
258
- }
259
- /** Sends another message, within 15 minutes of the interaction. */
260
- async followUp(options) {
261
- const { body, files } = toCallbackMessage(options);
262
- return this.#wrap(await this.client.rest.post(this.#webhookPath(), {
263
- body,
264
- files,
265
- }));
266
- }
267
- }
268
- function toCallbackMessage(options) {
269
- const { ephemeral, ...rest } = typeof options === 'string' ? { content: options } : options;
270
- const { body, files } = toMessageBody(rest);
271
- if (ephemeral)
272
- body.flags = (body.flags ?? 0) | EPHEMERAL;
273
- return { body, files };
274
- }
@@ -1,70 +0,0 @@
1
- import type { Client } from '../discord/client.js';
2
- import type { APIGuildMember, APIUser, Snowflake } from '../discord/types.js';
3
- import { type BanOptions, Guild } from './Guild.js';
4
- import type { Message } from './Message.js';
5
- import { User } from './User.js';
6
- import { type ImageOptions, type MessageOptions } from './utils.js';
7
- /** Member data as sent by the different events: some fields may be missing. */
8
- export type APIMemberData = Partial<APIGuildMember> & {
9
- user: APIUser;
10
- roles: Snowflake[];
11
- };
12
- /**
13
- * A user in a server.
14
- * https://docs.discord.com/developers/resources/guild#guild-member-object
15
- */
16
- export declare class Member {
17
- readonly client: Client;
18
- readonly guildId: Snowflake;
19
- readonly raw: APIMemberData;
20
- readonly id: Snowflake;
21
- readonly user: User;
22
- /** Nickname in this server. */
23
- readonly nick: string | null;
24
- /** Role ids, without the @everyone role. */
25
- readonly roles: Snowflake[];
26
- readonly joinedAt: Date | null;
27
- /** When the member started boosting the server. */
28
- readonly premiumSince: Date | null;
29
- /** True until the member passes Membership Screening. */
30
- readonly pending: boolean;
31
- /** Server avatar hash, if the member set one. */
32
- readonly avatar: string | null;
33
- /** End of the member's timeout, null when not timed out. */
34
- readonly communicationDisabledUntil: Date | null;
35
- /** Permissions in the channel, sent with interactions only. */
36
- readonly permissions: string | undefined;
37
- constructor(client: Client, guildId: Snowflake, raw: APIMemberData);
38
- get guild(): Guild;
39
- /** Name shown in this server: nickname, display name or username. */
40
- get displayName(): string;
41
- get isTimedOut(): boolean;
42
- hasRole(roleId: Snowflake): boolean;
43
- /** Mention, e.g. `${member}` in a message. */
44
- toString(): string;
45
- /** Avatar shown in this server: server avatar, user avatar or default avatar. */
46
- displayAvatarURL(options?: ImageOptions): string;
47
- /** Sends a direct message. */
48
- send(options: MessageOptions): Promise<Message>;
49
- kick(reason?: string): Promise<void>;
50
- ban(options?: BanOptions): Promise<void>;
51
- /**
52
- * Times the member out for `duration` milliseconds (up to 28 days), or
53
- * removes the timeout with null.
54
- * https://docs.discord.com/developers/resources/guild#modify-guild-member
55
- */
56
- timeout(duration: number | null, reason?: string): Promise<Member>;
57
- /** Null removes the nickname. */
58
- setNickname(nick: string | null, reason?: string): Promise<Member>;
59
- /** https://docs.discord.com/developers/resources/guild#add-guild-member-role */
60
- addRole(roleId: Snowflake, reason?: string): Promise<void>;
61
- /** https://docs.discord.com/developers/resources/guild#remove-guild-member-role */
62
- removeRole(roleId: Snowflake, reason?: string): Promise<void>;
63
- /**
64
- * Updates the member with fields of the documented JSON params (snake_case:
65
- * nick, roles, mute, deaf, channel_id, communication_disabled_until, flags).
66
- * https://docs.discord.com/developers/resources/guild#modify-guild-member
67
- */
68
- edit(data: Record<string, unknown>, reason?: string): Promise<Member>;
69
- fetch(): Promise<Member>;
70
- }