djs-selfbot-v13 3.1.6 → 3.1.7

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 (148) hide show
  1. package/README.md +31 -16
  2. package/package.json +15 -8
  3. package/src/client/BaseClient.js +3 -2
  4. package/src/client/Client.js +539 -187
  5. package/src/client/actions/Action.js +13 -18
  6. package/src/client/actions/ActionsManager.js +1 -7
  7. package/src/client/actions/AutoModerationActionExecution.js +0 -1
  8. package/src/client/actions/AutoModerationRuleCreate.js +0 -1
  9. package/src/client/actions/AutoModerationRuleDelete.js +0 -1
  10. package/src/client/actions/AutoModerationRuleUpdate.js +0 -1
  11. package/src/client/actions/InteractionCreate.js +115 -0
  12. package/src/client/actions/MessageCreate.js +4 -0
  13. package/src/client/actions/PresenceUpdate.js +16 -17
  14. package/src/client/websocket/WebSocketManager.js +31 -11
  15. package/src/client/websocket/WebSocketShard.js +38 -39
  16. package/src/client/websocket/handlers/APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE.js +23 -0
  17. package/src/client/websocket/handlers/CALL_CREATE.js +3 -3
  18. package/src/client/websocket/handlers/CALL_DELETE.js +2 -2
  19. package/src/client/websocket/handlers/CALL_UPDATE.js +2 -2
  20. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +13 -16
  21. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +11 -11
  22. package/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js +11 -0
  23. package/src/client/websocket/handlers/GUILD_CREATE.js +0 -7
  24. package/src/client/websocket/handlers/GUILD_MEMBER_LIST_UPDATE.js +55 -0
  25. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +0 -0
  26. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +0 -0
  27. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js +0 -0
  28. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +0 -0
  29. package/src/client/websocket/handlers/INTERACTION_CREATE.js +16 -0
  30. package/src/client/websocket/handlers/INTERACTION_FAILURE.js +18 -0
  31. package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +0 -1
  32. package/src/client/websocket/handlers/INTERACTION_SUCCESS.js +30 -0
  33. package/src/client/websocket/handlers/MESSAGE_ACK.js +16 -0
  34. package/src/client/websocket/handlers/READY.js +137 -47
  35. package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +5 -7
  36. package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +4 -6
  37. package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +9 -32
  38. package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +0 -0
  39. package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +8 -2
  40. package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +1 -1
  41. package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +5 -1
  42. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +0 -0
  43. package/src/client/websocket/handlers/index.js +20 -15
  44. package/src/errors/Messages.js +69 -24
  45. package/src/index.js +43 -12
  46. package/src/managers/ApplicationCommandManager.js +12 -9
  47. package/src/managers/ApplicationCommandPermissionsManager.js +11 -3
  48. package/src/managers/ChannelManager.js +4 -2
  49. package/src/managers/ClientUserSettingManager.js +279 -161
  50. package/src/managers/DeveloperPortalManager.js +104 -0
  51. package/src/managers/GuildApplicationCommandManager.js +28 -0
  52. package/src/managers/GuildBanManager.js +1 -1
  53. package/src/managers/GuildChannelManager.js +0 -2
  54. package/src/managers/GuildFolderManager.js +24 -0
  55. package/src/managers/GuildForumThreadManager.js +28 -22
  56. package/src/managers/GuildMemberManager.js +216 -40
  57. package/src/managers/GuildSettingManager.js +15 -22
  58. package/src/managers/MessageManager.js +44 -42
  59. package/src/managers/PermissionOverwriteManager.js +1 -1
  60. package/src/managers/ReactionUserManager.js +5 -5
  61. package/src/managers/RelationshipManager.js +74 -81
  62. package/src/managers/SessionManager.js +57 -0
  63. package/src/managers/ThreadManager.js +45 -12
  64. package/src/managers/ThreadMemberManager.js +1 -1
  65. package/src/managers/UserManager.js +10 -6
  66. package/src/rest/APIRequest.js +20 -42
  67. package/src/rest/CaptchaSolver.js +132 -0
  68. package/src/rest/DiscordAPIError.js +16 -17
  69. package/src/rest/RESTManager.js +21 -1
  70. package/src/rest/RequestHandler.js +21 -35
  71. package/src/structures/ApplicationCommand.js +456 -19
  72. package/src/structures/ApplicationRoleConnectionMetadata.js +0 -3
  73. package/src/structures/AutoModerationRule.js +5 -5
  74. package/src/structures/AutocompleteInteraction.js +0 -1
  75. package/src/structures/BaseGuildTextChannel.js +12 -10
  76. package/src/structures/BaseGuildVoiceChannel.js +18 -16
  77. package/src/structures/{CallState.js → Call.js} +12 -17
  78. package/src/structures/CategoryChannel.js +0 -2
  79. package/src/structures/Channel.js +3 -2
  80. package/src/structures/ClientApplication.js +204 -0
  81. package/src/structures/ClientPresence.js +8 -12
  82. package/src/structures/ClientUser.js +336 -117
  83. package/src/structures/ContextMenuInteraction.js +1 -1
  84. package/src/structures/DMChannel.js +92 -29
  85. package/src/structures/DeveloperPortalApplication.js +520 -0
  86. package/src/structures/ForumChannel.js +10 -0
  87. package/src/structures/Guild.js +271 -135
  88. package/src/structures/GuildAuditLogs.js +5 -0
  89. package/src/structures/GuildChannel.js +2 -16
  90. package/src/structures/GuildFolder.js +75 -0
  91. package/src/structures/GuildMember.js +145 -27
  92. package/src/structures/Interaction.js +62 -1
  93. package/src/structures/InteractionResponse.js +114 -0
  94. package/src/structures/Invite.js +52 -35
  95. package/src/structures/Message.js +202 -222
  96. package/src/structures/MessageAttachment.js +0 -11
  97. package/src/structures/MessageButton.js +67 -1
  98. package/src/structures/MessageEmbed.js +1 -1
  99. package/src/structures/MessageMentions.js +2 -3
  100. package/src/structures/MessagePayload.js +46 -4
  101. package/src/structures/MessageReaction.js +1 -1
  102. package/src/structures/MessageSelectMenu.js +252 -1
  103. package/src/structures/Modal.js +180 -75
  104. package/src/structures/PartialGroupDMChannel.js +433 -0
  105. package/src/structures/Presence.js +2 -2
  106. package/src/structures/RichPresence.js +34 -14
  107. package/src/structures/Role.js +2 -18
  108. package/src/structures/SelectMenuInteraction.js +151 -2
  109. package/src/structures/Session.js +81 -0
  110. package/src/structures/Team.js +49 -0
  111. package/src/structures/TextInputComponent.js +70 -0
  112. package/src/structures/ThreadChannel.js +19 -0
  113. package/src/structures/User.js +345 -117
  114. package/src/structures/UserContextMenuInteraction.js +2 -2
  115. package/src/structures/VoiceState.js +39 -74
  116. package/src/structures/WebEmbed.js +52 -38
  117. package/src/structures/Webhook.js +11 -17
  118. package/src/structures/interfaces/Application.js +23 -146
  119. package/src/structures/interfaces/TextBasedChannel.js +256 -411
  120. package/src/util/ApplicationFlags.js +1 -1
  121. package/src/util/Constants.js +284 -106
  122. package/src/util/Formatters.js +2 -16
  123. package/src/util/LimitedCollection.js +1 -1
  124. package/src/util/Options.js +68 -48
  125. package/src/util/Permissions.js +0 -5
  126. package/src/util/PurchasedFlags.js +0 -2
  127. package/src/util/RemoteAuth.js +356 -221
  128. package/src/util/Sweepers.js +1 -1
  129. package/src/util/Util.js +36 -76
  130. package/src/util/Voice.js +1456 -0
  131. package/src/util/arRPC/index.js +229 -0
  132. package/src/util/arRPC/process/detectable.json +1 -0
  133. package/src/util/arRPC/process/index.js +102 -0
  134. package/src/util/arRPC/process/native/index.js +5 -0
  135. package/src/util/arRPC/process/native/linux.js +37 -0
  136. package/src/util/arRPC/process/native/win32.js +25 -0
  137. package/src/util/arRPC/transports/ipc.js +281 -0
  138. package/src/util/arRPC/transports/websocket.js +128 -0
  139. package/typings/enums.d.ts +73 -18
  140. package/typings/index.d.ts +1249 -897
  141. package/typings/rawDataTypes.d.ts +9 -68
  142. package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +0 -78
  143. package/src/client/websocket/handlers/VOICE_CHANNEL_STATUS_UPDATE.js +0 -12
  144. package/src/managers/UserNoteManager.js +0 -53
  145. package/src/structures/GroupDMChannel.js +0 -387
  146. package/src/util/AttachmentFlags.js +0 -38
  147. package/src/util/InviteFlags.js +0 -29
  148. package/src/util/RoleFlags.js +0 -37
@@ -5,12 +5,14 @@ import {
5
5
  APIApplication,
6
6
  APIApplicationCommand,
7
7
  APIApplicationCommandInteraction,
8
+ APIAttachment,
8
9
  APIAuditLog,
9
10
  APIAuditLogEntry,
10
11
  APIBan,
11
12
  APIChannel,
12
13
  APIEmoji,
13
14
  APIExtendedInvite,
15
+ APIGuild,
14
16
  APIGuildIntegration,
15
17
  APIGuildIntegrationApplication,
16
18
  APIGuildMember,
@@ -74,26 +76,21 @@ import {
74
76
  RESTPostAPIWebhookWithTokenJSONBody,
75
77
  Snowflake,
76
78
  APIGuildScheduledEvent,
79
+ APIActionRowComponent,
77
80
  APITextInputComponent,
81
+ APIModalActionRowComponent,
78
82
  APIModalSubmitInteraction,
79
- Permissions,
80
- GuildDefaultMessageNotifications,
81
- GuildExplicitContentFilter,
82
- GuildMFALevel,
83
- GuildSystemChannelFlags,
84
- GuildPremiumTier,
85
- GuildNSFWLevel,
86
- GuildHubType,
87
- GuildVerificationLevel,
88
- GuildFeature,
89
83
  LocalizationMap,
90
84
  } from 'discord-api-types/v9';
91
- import { GuildChannel, Guild, PermissionOverwrites } from '.';
85
+ import { GuildChannel, Guild, PermissionOverwrites, InteractionType } from '.';
86
+
92
87
  import type {
93
88
  AutoModerationActionTypes,
94
89
  AutoModerationRuleEventTypes,
95
90
  AutoModerationRuleKeywordPresetTypes,
96
91
  AutoModerationRuleTriggerTypes,
92
+ InteractionTypes,
93
+ MessageComponentTypes,
97
94
  ApplicationRoleConnectionMetadataTypes,
98
95
  } from './enums';
99
96
 
@@ -173,20 +170,7 @@ export type RawInviteStageInstance = APIInviteStageInstance;
173
170
  export type RawMessageData = APIMessage;
174
171
  export type RawPartialMessageData = GatewayMessageUpdateDispatchData;
175
172
 
176
- export interface RawMessageAttachmentData {
177
- id: Snowflake;
178
- filename: string;
179
- description?: string;
180
- content_type?: string;
181
- size: number;
182
- url: string;
183
- proxy_url: string;
184
- height?: number | null;
185
- width?: number | null;
186
- ephemeral?: boolean;
187
- duration_secs?: number;
188
- waveform?: string;
189
- }
173
+ export type RawMessageAttachmentData = APIAttachment;
190
174
 
191
175
  export type RawMessagePayloadData =
192
176
  | RESTPostAPIChannelMessageJSONBody
@@ -287,49 +271,6 @@ export interface APIAutoModerationRuleTriggerMetadata {
287
271
  allow_list?: string[];
288
272
  regex_patterns?: string[];
289
273
  mention_total_limit?: number;
290
- mention_raid_protection_enabled?: boolean;
291
- }
292
-
293
- export interface APIGuild extends APIPartialGuild {
294
- icon_hash?: string | null;
295
- discovery_splash: string | null;
296
- owner?: boolean;
297
- owner_id: Snowflake;
298
- permissions?: Permissions;
299
- region: string;
300
- afk_channel_id: Snowflake | null;
301
- afk_timeout: number;
302
- widget_enabled?: boolean;
303
- widget_channel_id?: Snowflake | null;
304
- verification_level: GuildVerificationLevel;
305
- default_message_notifications: GuildDefaultMessageNotifications;
306
- explicit_content_filter: GuildExplicitContentFilter;
307
- roles: APIRole[];
308
- emojis: APIEmoji[];
309
- features: GuildFeature[];
310
- mfa_level: GuildMFALevel;
311
- application_id: Snowflake | null;
312
- system_channel_id: Snowflake | null;
313
- system_channel_flags: GuildSystemChannelFlags;
314
- rules_channel_id: Snowflake | null;
315
- max_presences?: number | null;
316
- max_members?: number;
317
- vanity_url_code: string | null;
318
- description: string | null;
319
- banner: string | null;
320
- premium_tier: GuildPremiumTier;
321
- premium_subscription_count?: number;
322
- preferred_locale: string;
323
- public_updates_channel_id: Snowflake | null;
324
- max_video_channel_users?: number;
325
- approximate_member_count?: number;
326
- approximate_presence_count?: number;
327
- welcome_screen?: APIGuildWelcomeScreen;
328
- nsfw_level: GuildNSFWLevel;
329
- stickers: APISticker[];
330
- premium_progress_bar_enabled: boolean;
331
- hub_type: GuildHubType | null;
332
- safety_alerts_channel_id: Snowflake | null;
333
274
  }
334
275
 
335
276
  export interface APIApplicationRoleConnectionMetadata {
@@ -1,78 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = (client, { d: data }) => {
4
- let msg;
5
- switch (data.required_action) {
6
- case undefined:
7
- case null: {
8
- msg = 'All required actions have been completed.';
9
- break;
10
- }
11
- case 'AGREEMENTS': {
12
- msg = 'You need to accept the new Terms of Service and Privacy Policy.';
13
- // https://discord.com/api/v9/users/@me/agreements
14
- client.api
15
- .users('@me')
16
- .agreements.patch({
17
- data: {
18
- terms: true,
19
- privacy: true,
20
- },
21
- })
22
- .then(() => {
23
- client.emit(
24
- 'debug',
25
- '[USER_REQUIRED_ACTION] Successfully accepted the new Terms of Service and Privacy Policy.',
26
- );
27
- })
28
- .catch(e => {
29
- client.emit(
30
- 'debug',
31
- `[USER_REQUIRED_ACTION] Failed to accept the new Terms of Service and Privacy Policy: ${e}`,
32
- );
33
- });
34
- break;
35
- }
36
- case 'REQUIRE_CAPTCHA': {
37
- msg = 'You need to complete a captcha.';
38
- break;
39
- }
40
- case 'REQUIRE_VERIFIED_EMAIL': {
41
- msg = 'You need to verify your email.';
42
- break;
43
- }
44
- case 'REQUIRE_REVERIFIED_EMAIL': {
45
- msg = 'You need to reverify your email.';
46
- break;
47
- }
48
- case 'REQUIRE_VERIFIED_PHONE': {
49
- msg = 'You need to verify your phone number.';
50
- break;
51
- }
52
- case 'REQUIRE_REVERIFIED_PHONE': {
53
- msg = 'You need to reverify your phone number.';
54
- break;
55
- }
56
- case 'REQUIRE_VERIFIED_EMAIL_OR_VERIFIED_PHONE': {
57
- msg = 'You need to verify your email or verify your phone number.';
58
- break;
59
- }
60
- case 'REQUIRE_REVERIFIED_EMAIL_OR_VERIFIED_PHONE': {
61
- msg = 'You need to reverify your email or verify your phone number.';
62
- break;
63
- }
64
- case 'REQUIRE_VERIFIED_EMAIL_OR_REVERIFIED_PHONE': {
65
- msg = 'You need to verify your email or reverify your phone number.';
66
- break;
67
- }
68
- case 'REQUIRE_REVERIFIED_EMAIL_OR_REVERIFIED_PHONE': {
69
- msg = 'You need to reverify your email or reverify your phone number.';
70
- break;
71
- }
72
- default: {
73
- msg = `Unknown required action: ${data.required_action}`;
74
- break;
75
- }
76
- }
77
- client.emit('debug', `[USER_REQUIRED_ACTION] ${msg}`);
78
- };
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- const { Events } = require('../../../util/Constants');
4
-
5
- module.exports = (client, { d: data }) => {
6
- const channel = client.channels.cache.get(data.id);
7
- if (channel) {
8
- const old = channel._clone();
9
- channel.status = data.status;
10
- client.emit(Events.CHANNEL_UPDATE, old, channel);
11
- }
12
- };
@@ -1,53 +0,0 @@
1
- 'use strict';
2
-
3
- const { Collection } = require('@discordjs/collection');
4
- const BaseManager = require('./BaseManager');
5
-
6
- /**
7
- * Manages API methods for Client and stores their cache.
8
- * @extends {BaseManager}
9
- */
10
- class UserNoteManager extends BaseManager {
11
- constructor(client, data = {}) {
12
- super(client);
13
- /**
14
- * Cache User Note
15
- * @type {Collection<Snowflake, string>}
16
- */
17
- this.cache = new Collection(Object.entries(data));
18
- }
19
-
20
- _reload(data = {}) {
21
- this.cache = new Collection(Object.entries(data));
22
- return this;
23
- }
24
-
25
- async updateNote(id, note = null) {
26
- await this.client.api.users['@me'].notes(id).put({ data: { note } });
27
- if (!note) this.cache.delete(id, note);
28
- else this.cache.set(id, note);
29
- return this;
30
- }
31
-
32
- /**
33
- * Obtains a user from Discord, or the user cache if it's already available.
34
- * @param {UserResolvable} user The user to fetch
35
- * @param {BaseFetchOptions} [options] Additional options for this fetch
36
- * @returns {Promise<string>}
37
- */
38
- async fetch(user, { cache = true, force = false } = {}) {
39
- const id = this.resolveId(user);
40
- if (!force) {
41
- const existing = this.cache.get(id);
42
- if (existing) return existing;
43
- }
44
- const data = await this.client.api.users['@me'].notes[id]
45
- .get()
46
- .then(d => d.note)
47
- .catch(() => '');
48
- if (cache) this.cache.set(id, data);
49
- return data;
50
- }
51
- }
52
-
53
- module.exports = UserNoteManager;
@@ -1,387 +0,0 @@
1
- 'use strict';
2
-
3
- const { Collection } = require('@discordjs/collection');
4
- const { Channel } = require('./Channel');
5
- const Invite = require('./Invite');
6
- const TextBasedChannel = require('./interfaces/TextBasedChannel');
7
- const MessageManager = require('../managers/MessageManager');
8
- const { Status, Opcodes } = require('../util/Constants');
9
- const DataResolver = require('../util/DataResolver');
10
-
11
- /**
12
- * Represents a Group DM Channel on Discord.
13
- * @extends {Channel}
14
- * @implements {TextBasedChannel}
15
- */
16
- class GroupDMChannel extends Channel {
17
- constructor(client, data) {
18
- super(client, data);
19
- // Override the channel type so partials have a known type
20
- this.type = 'GROUP_DM';
21
-
22
- /**
23
- * A manager of the messages belonging to this channel
24
- * @type {MessageManager}
25
- */
26
- this.messages = new MessageManager(this);
27
- }
28
-
29
- _patch(data) {
30
- super._patch(data);
31
-
32
- if ('recipients' in data && Array.isArray(data.recipients)) {
33
- this._recipients = data.recipients;
34
- data.recipients.forEach(u => this.client.users._add(u));
35
- } else {
36
- this._recipients = [];
37
- }
38
-
39
- if ('last_message_id' in data) {
40
- /**
41
- * The channel's last message id, if one was sent
42
- * @type {?Snowflake}
43
- */
44
- this.lastMessageId = data.last_message_id;
45
- }
46
-
47
- if ('last_pin_timestamp' in data) {
48
- /**
49
- * The timestamp when the last pinned message was pinned, if there was one
50
- * @type {?number}
51
- */
52
- this.lastPinTimestamp = new Date(data.last_pin_timestamp).getTime();
53
- } else {
54
- this.lastPinTimestamp ??= null;
55
- }
56
-
57
- if ('owner_id' in data) {
58
- /**
59
- * Owner ID
60
- * @type {Snowflake}
61
- */
62
- this.ownerId = data.owner_id;
63
- }
64
-
65
- if ('name' in data) {
66
- /**
67
- * The name of this Group DM Channel
68
- * @type {?string}
69
- */
70
- this.name = data.name;
71
- }
72
-
73
- if ('icon' in data) {
74
- /**
75
- * The hash of the channel icon
76
- * @type {?string}
77
- */
78
- this.icon = data.icon;
79
- }
80
- }
81
-
82
- /**
83
- * The URL to this channel's icon.
84
- * @param {StaticImageURLOptions} [options={}] Options for the Image URL
85
- * @returns {?string}
86
- */
87
- iconURL({ format, size } = {}) {
88
- return this.icon && this.client.rest.cdn.GDMIcon(this.id, this.icon, format, size);
89
- }
90
-
91
- /**
92
- * The recipients of this Group DM Channel.
93
- * @type {Collection<Snowflake, User>}
94
- * @readonly
95
- */
96
- get recipients() {
97
- const collect = new Collection();
98
- this._recipients.map(recipient => collect.set(recipient.id, this.client.users.cache.get(recipient.id)));
99
- collect.set(this.client.user.id, this.client.user);
100
- return collect;
101
- }
102
-
103
- /**
104
- * The owner of this Group DM Channel
105
- * @type {?User}
106
- * @readonly
107
- */
108
- get owner() {
109
- return this.client.users.cache.get(this.ownerId);
110
- }
111
-
112
- /**
113
- * Whether this DMChannel is a partial
114
- * @type {boolean}
115
- * @readonly
116
- */
117
- get partial() {
118
- return typeof this.lastMessageId === 'undefined';
119
- }
120
-
121
- /**
122
- * Leave this Group DM Channel.
123
- * @param {?boolean} slient Leave without notifying other members
124
- * @returns {Promise<GroupDMChannel>}
125
- * @example
126
- * // Delete the channel
127
- * channel.delete()
128
- * .then(console.log)
129
- * .catch(console.error);
130
- */
131
- async delete(slient = false) {
132
- if (typeof slient === 'boolean' && slient) {
133
- await this.client.api.channels[this.id].delete({
134
- query: {
135
- silent: true,
136
- },
137
- });
138
- } else {
139
- await this.client.api.channels[this.id].delete();
140
- }
141
- return this;
142
- }
143
-
144
- /**
145
- * When concatenated with a string, this automatically returns the recipient's mention instead of the
146
- * GroupDMChannel object.
147
- * @returns {string}
148
- * @example
149
- * // Logs: Hello from Group Test!
150
- * console.log(`Hello from ${channel}!`);
151
- */
152
- toString() {
153
- return (
154
- this.name ??
155
- this._recipients
156
- .filter(user => user.id !== this.client.user.id)
157
- .map(user => user.username)
158
- .join(', ')
159
- );
160
- }
161
-
162
- toJSON() {
163
- const json = super.toJSON({
164
- createdTimestamp: true,
165
- });
166
- json.iconURL = this.iconURL();
167
- return json;
168
- }
169
-
170
- /**
171
- * The data for editing a channe;.
172
- * @typedef {Object} GroupDMChannelEditData
173
- * @property {string} [name] The name of the channel
174
- * @property {?(BufferResolvable|Base64Resolvable)} [icon] The icon of the channel
175
- * @property {GuildMemberResolvable} [owner] The owner of the channel
176
- */
177
-
178
- /**
179
- * Edit channel data
180
- * @param {GroupDMChannelEditData} data Data
181
- * @returns {Promise<GroupDMChannel>}
182
- * @example
183
- * // Set the channel name
184
- * channel.edit({
185
- * name: 'Group Test',
186
- * })
187
- * .then(updated => console.log(`New channel name ${updated}`))
188
- * .catch(console.error);
189
- */
190
- async edit(data) {
191
- const _data = {};
192
- if ('name' in data) _data.name = data.name?.trim() ?? null;
193
- if (typeof data.icon !== 'undefined') {
194
- _data.icon = await DataResolver.resolveImage(data.icon);
195
- }
196
- if ('owner' in data) {
197
- _data.owner = data.owner;
198
- }
199
- const newData = await this.client.api.channels[this.id].patch({
200
- data: _data,
201
- });
202
-
203
- return this.client.actions.ChannelUpdate.handle(newData).updated;
204
- }
205
-
206
- /**
207
- * Renames this Group DM Channel.
208
- * @param {?string} name Name of the channel
209
- * @returns {Promise<GroupDMChannel>}
210
- */
211
- setName(name) {
212
- return this.edit({ name });
213
- }
214
-
215
- /**
216
- * Sets the icon of this Group DM Channel.
217
- * @param {?(Base64Resolvable|BufferResolvable)} icon Icon of the channel
218
- * @returns {Promise<GroupDMChannel>}
219
- */
220
- setIcon(icon) {
221
- return this.edit({ icon });
222
- }
223
-
224
- /**
225
- * Changes the owner of this Group DM Channel.
226
- * @param {UserResolvable} user User to transfer ownership to
227
- * @returns {Promise<GroupDMChannel>}
228
- */
229
- setOwner(user) {
230
- const id = this.client.users.resolveId(user);
231
- if (this.ownerId === id) {
232
- return Promise.resolve(this);
233
- }
234
- return this.edit({ owner: id });
235
- }
236
-
237
- /**
238
- * Adds a user to this Group DM Channel.
239
- * @param {UserResolvable} user User to add to the group
240
- * @returns {Promise<GroupDMChannel>}
241
- */
242
- async addUser(user) {
243
- user = this.client.users.resolveId(user);
244
- await this.client.api.channels[this.id].recipients[user].put();
245
- return this;
246
- }
247
-
248
- /**
249
- * Removes a user from this Group DM Channel.
250
- * @param {UserResolvable} user User to remove from the group
251
- * @returns {Promise<GroupDMChannel>}
252
- */
253
- async removeUser(user) {
254
- user = this.client.users.resolveId(user);
255
- await this.client.api.channels[this.id].recipients[user].delete();
256
- return this;
257
- }
258
-
259
- /**
260
- * Gets the invite for this Group DM Channel.
261
- * @returns {Promise<Invite>}
262
- */
263
- async getInvite() {
264
- const inviteCode = await this.client.api.channels(this.id).invites.post({
265
- data: {
266
- max_age: 86400,
267
- },
268
- });
269
- return new Invite(this.client, inviteCode);
270
- }
271
-
272
- /**
273
- * Get all the invites for this Group DM Channel.
274
- * @returns {Promise<Collection<string, Invite>>}
275
- */
276
- async fetchAllInvite() {
277
- const invites = await this.client.api.channels(this.id).invites.get();
278
- return new Collection(invites.map(invite => [invite.code, new Invite(this.client, invite)]));
279
- }
280
-
281
- /**
282
- * Delete invites from this Group DM Channel.
283
- * @param {InviteResolvable} invite Invite to add to the channel
284
- * @returns {Promise<GroupDMChannel>}
285
- */
286
- async removeInvite(invite) {
287
- // Resolve
288
- let code = invite?.code;
289
- if (!code && URL.canParse(invite)) code = new URL(invite).pathname.slice(1);
290
- else code = invite;
291
- await this.client.api.channels(this.id).invites[invite].delete();
292
- return this;
293
- }
294
-
295
- /**
296
- * Ring the user's phone / PC (call)
297
- * @param {UserResolvable[]} [recipients] Array of recipients
298
- * @returns {Promise<any>}
299
- */
300
- ring(recipients) {
301
- if (!recipients || !Array.isArray(recipients) || recipients.length == 0) recipients = null;
302
- recipients = recipients.map(r => this.client.users.resolveId(r)).filter(r => r && this.recipients.get(r));
303
- return this.client.api.channels(this.id).call.ring.post({
304
- data: {
305
- recipients,
306
- },
307
- });
308
- }
309
-
310
- /**
311
- * Sync VoiceState of this Group DMChannel.
312
- * @returns {undefined}
313
- */
314
- sync() {
315
- this.client.ws.broadcast({
316
- op: Opcodes.DM_UPDATE,
317
- d: {
318
- channel_id: this.id,
319
- },
320
- });
321
- }
322
-
323
- /**
324
- * The user in this voice-based channel
325
- * @type {Collection<Snowflake, User>}
326
- * @readonly
327
- */
328
- get voiceUsers() {
329
- const coll = new Collection();
330
- for (const state of this.client.voiceStates.cache.values()) {
331
- if (state.channelId === this.id && state.user) {
332
- coll.set(state.id, state.user);
333
- }
334
- }
335
- return coll;
336
- }
337
-
338
- /**
339
- * Get current shard
340
- * @type {WebSocketShard}
341
- * @readonly
342
- */
343
- get shard() {
344
- return this.client.ws.shards.first();
345
- }
346
-
347
- /**
348
- * The voice state adapter for this client that can be used with @discordjs/voice to play audio in DM / Group DM channels.
349
- * @type {?Function}
350
- * @readonly
351
- */
352
- get voiceAdapterCreator() {
353
- return methods => {
354
- this.client.voice.adapters.set(this.id, methods);
355
- return {
356
- sendPayload: data => {
357
- if (this.shard.status !== Status.READY) return false;
358
- this.shard.send(data);
359
- return true;
360
- },
361
- destroy: () => {
362
- this.client.voice.adapters.delete(this.id);
363
- },
364
- };
365
- };
366
- }
367
-
368
- // These are here only for documentation purposes - they are implemented by TextBasedChannel
369
- /* eslint-disable no-empty-function */
370
- get lastMessage() {}
371
- get lastPinAt() {}
372
- send() {}
373
- sendTyping() {}
374
- createMessageCollector() {}
375
- awaitMessages() {}
376
- // Doesn't work on DM channels; setRateLimitPerUser() {}
377
- // Doesn't work on DM channels; setNSFW() {}
378
- }
379
-
380
- TextBasedChannel.applyToClass(GroupDMChannel, true, [
381
- 'fetchWebhooks',
382
- 'createWebhook',
383
- 'setRateLimitPerUser',
384
- 'setNSFW',
385
- ]);
386
-
387
- module.exports = GroupDMChannel;
@@ -1,38 +0,0 @@
1
- 'use strict';
2
-
3
- const BitField = require('./BitField');
4
-
5
- /**
6
- * Data structure that makes it easy to interact with an {@link GuildMember#flags} bitfield.
7
- * @extends {BitField}
8
- */
9
- class AttachmentFlags extends BitField {}
10
-
11
- /**
12
- * @name AttachmentFlags
13
- * @kind constructor
14
- * @memberof AttachmentFlags
15
- * @param {BitFieldResolvable} [bits=0] Bit(s) to read from
16
- */
17
-
18
- /* eslint-disable max-len */
19
- /**
20
- * Numeric guild member flags. All available properties:
21
- * * `IS_REMIX`
22
- * @type {Object}
23
- * @see {@link https://discord.com/developers/docs/resources/channel#attachment-object-attachment-structure-attachment-flags}
24
- */
25
- AttachmentFlags.FLAGS = {
26
- IS_REMIX: 1 << 2,
27
- };
28
-
29
- /**
30
- * Data that can be resolved to give a guild attachment bitfield. This can be:
31
- * * A string (see {@link AttachmentFlags.FLAGS})
32
- * * A attachment flag
33
- * * An instance of AttachmentFlags
34
- * * An Array of AttachmentFlagsResolvable
35
- * @typedef {string|number|AttachmentFlags|AttachmentFlagsResolvable[]} AttachmentFlagsResolvable
36
- */
37
-
38
- module.exports = AttachmentFlags;