discord.js 15.0.0-move-client-init.1761650119-a4c0a246f → 15.0.0-pr-11006.1765450224-e636950b2
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/package.json +18 -20
- package/src/client/Client.js +107 -14
- package/src/client/websocket/handlers/RATE_LIMITED.js +24 -0
- package/src/client/websocket/handlers/index.js +1 -0
- package/src/errors/DJSError.js +7 -3
- package/src/errors/ErrorCodes.js +2 -4
- package/src/errors/Messages.js +2 -3
- package/src/index.js +0 -3
- package/src/managers/CachedManager.js +5 -5
- package/src/managers/ChannelManager.js +10 -7
- package/src/managers/GuildBanManager.js +3 -3
- package/src/managers/GuildEmojiManager.js +2 -2
- package/src/managers/GuildEmojiRoleManager.js +9 -1
- package/src/managers/GuildMemberManager.js +44 -23
- package/src/managers/GuildMemberRoleManager.js +11 -2
- package/src/managers/MessageManager.js +25 -18
- package/src/structures/ApplicationCommand.js +4 -5
- package/src/structures/ClientApplication.js +2 -0
- package/src/structures/CommandInteraction.js +1 -1
- package/src/structures/Embed.js +1 -1
- package/src/structures/Guild.js +11 -1
- package/src/structures/GuildInvite.js +1 -1
- package/src/structures/GuildMember.js +12 -9
- package/src/structures/Message.js +18 -15
- package/src/structures/MessagePayload.js +21 -17
- package/src/structures/ModalComponentResolver.js +11 -0
- package/src/structures/ModalSubmitInteraction.js +23 -6
- package/src/structures/PermissionOverwrites.js +1 -1
- package/src/structures/Role.js +1 -1
- package/src/structures/ThreadChannel.js +1 -1
- package/src/structures/Webhook.js +6 -11
- package/src/structures/interfaces/TextBasedChannel.js +7 -9
- package/src/util/APITypes.js +10 -0
- package/src/util/Components.js +60 -42
- package/src/util/Constants.js +2 -0
- package/src/util/DataResolver.js +5 -2
- package/src/util/GuildMemberFlagsBitField.js +1 -1
- package/src/util/Options.js +9 -5
- package/src/util/Util.js +18 -13
- package/typings/index.d.mts +163 -171
- package/typings/index.d.ts +163 -171
- package/src/client/BaseClient.js +0 -131
- package/src/client/WebhookClient.js +0 -119
- package/src/structures/AttachmentBuilder.js +0 -185
package/src/client/BaseClient.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { REST, RESTEvents } = require('@discordjs/rest');
|
|
4
|
-
const { AsyncEventEmitter } = require('@vladfrangu/async_event_emitter');
|
|
5
|
-
const { Routes } = require('discord-api-types/v10');
|
|
6
|
-
const { DiscordjsTypeError, ErrorCodes } = require('../errors/index.js');
|
|
7
|
-
const { Events } = require('../util/Events.js');
|
|
8
|
-
const { Options } = require('../util/Options.js');
|
|
9
|
-
const { flatten } = require('../util/Util.js');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The base class for all clients.
|
|
13
|
-
*
|
|
14
|
-
* @extends {AsyncEventEmitter}
|
|
15
|
-
*/
|
|
16
|
-
class BaseClient extends AsyncEventEmitter {
|
|
17
|
-
constructor(options = {}) {
|
|
18
|
-
super();
|
|
19
|
-
|
|
20
|
-
if (typeof options !== 'object' || options === null) {
|
|
21
|
-
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const defaultOptions = Options.createDefault();
|
|
25
|
-
/**
|
|
26
|
-
* The options the client was instantiated with
|
|
27
|
-
*
|
|
28
|
-
* @type {ClientOptions}
|
|
29
|
-
*/
|
|
30
|
-
this.options = {
|
|
31
|
-
...defaultOptions,
|
|
32
|
-
...options,
|
|
33
|
-
presence: {
|
|
34
|
-
...defaultOptions.presence,
|
|
35
|
-
...options.presence,
|
|
36
|
-
},
|
|
37
|
-
sweepers: {
|
|
38
|
-
...defaultOptions.sweepers,
|
|
39
|
-
...options.sweepers,
|
|
40
|
-
},
|
|
41
|
-
ws: {
|
|
42
|
-
...defaultOptions.ws,
|
|
43
|
-
...options.ws,
|
|
44
|
-
},
|
|
45
|
-
rest: {
|
|
46
|
-
...defaultOptions.rest,
|
|
47
|
-
...options.rest,
|
|
48
|
-
userAgentAppendix: options.rest?.userAgentAppendix
|
|
49
|
-
? `${Options.userAgentAppendix} ${options.rest.userAgentAppendix}`
|
|
50
|
-
: Options.userAgentAppendix,
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The REST manager of the client
|
|
56
|
-
*
|
|
57
|
-
* @type {REST}
|
|
58
|
-
*/
|
|
59
|
-
this.rest = new REST(this.options.rest);
|
|
60
|
-
|
|
61
|
-
this.rest.on(RESTEvents.Debug, message => this.emit(Events.Debug, message));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Destroys all assets used by the base client.
|
|
66
|
-
*
|
|
67
|
-
* @returns {void}
|
|
68
|
-
*/
|
|
69
|
-
destroy() {
|
|
70
|
-
this.rest.clearHashSweeper();
|
|
71
|
-
this.rest.clearHandlerSweeper();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Options used for deleting a webhook.
|
|
76
|
-
*
|
|
77
|
-
* @typedef {Object} WebhookDeleteOptions
|
|
78
|
-
* @property {string} [token] Token of the webhook
|
|
79
|
-
* @property {string} [reason] The reason for deleting the webhook
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Deletes a webhook.
|
|
84
|
-
*
|
|
85
|
-
* @param {Snowflake} id The webhook's id
|
|
86
|
-
* @param {WebhookDeleteOptions} [options] Options for deleting the webhook
|
|
87
|
-
* @returns {Promise<void>}
|
|
88
|
-
*/
|
|
89
|
-
async deleteWebhook(id, { token, reason } = {}) {
|
|
90
|
-
await this.rest.delete(Routes.webhook(id, token), { auth: !token, reason });
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Increments max listeners by one, if they are not zero.
|
|
95
|
-
*
|
|
96
|
-
* @private
|
|
97
|
-
*/
|
|
98
|
-
incrementMaxListeners() {
|
|
99
|
-
const maxListeners = this.getMaxListeners();
|
|
100
|
-
if (maxListeners !== 0) {
|
|
101
|
-
this.setMaxListeners(maxListeners + 1);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Decrements max listeners by one, if they are not zero.
|
|
107
|
-
*
|
|
108
|
-
* @private
|
|
109
|
-
*/
|
|
110
|
-
decrementMaxListeners() {
|
|
111
|
-
const maxListeners = this.getMaxListeners();
|
|
112
|
-
if (maxListeners !== 0) {
|
|
113
|
-
this.setMaxListeners(maxListeners - 1);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
toJSON(...props) {
|
|
118
|
-
return flatten(this, ...props);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async [Symbol.asyncDispose]() {
|
|
122
|
-
await this.destroy();
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
exports.BaseClient = BaseClient;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* @external REST
|
|
130
|
-
* @see {@link https://discord.js.org/docs/packages/rest/stable/REST:Class}
|
|
131
|
-
*/
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { DiscordjsError, ErrorCodes } = require('../errors/index.js');
|
|
4
|
-
const { Webhook } = require('../structures/Webhook.js');
|
|
5
|
-
const { parseWebhookURL } = require('../util/Util.js');
|
|
6
|
-
const { BaseClient } = require('./BaseClient.js');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The webhook client.
|
|
10
|
-
*
|
|
11
|
-
* @implements {Webhook}
|
|
12
|
-
* @extends {BaseClient}
|
|
13
|
-
*/
|
|
14
|
-
class WebhookClient extends BaseClient {
|
|
15
|
-
/**
|
|
16
|
-
* Represents the credentials used for a webhook in the form of its id and token.
|
|
17
|
-
*
|
|
18
|
-
* @typedef {Object} WebhookClientDataIdWithToken
|
|
19
|
-
* @property {Snowflake} id The webhook's id
|
|
20
|
-
* @property {string} token The webhook's token
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Represents the credentials used for a webhook in the form of a URL.
|
|
25
|
-
*
|
|
26
|
-
* @typedef {Object} WebhookClientDataURL
|
|
27
|
-
* @property {string} url The full URL for the webhook
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Represents the credentials used for a webhook.
|
|
32
|
-
*
|
|
33
|
-
* @typedef {WebhookClientDataIdWithToken|WebhookClientDataURL} WebhookClientData
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Options for a webhook client.
|
|
38
|
-
*
|
|
39
|
-
* @typedef {Object} WebhookClientOptions
|
|
40
|
-
* @property {MessageMentionOptions} [allowedMentions] Default value for {@link BaseMessageOptions#allowedMentions}
|
|
41
|
-
* @property {RESTOptions} [rest] Options for the REST manager
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @param {WebhookClientData} data The data of the webhook
|
|
46
|
-
* @param {WebhookClientOptions} [options] Options for the webhook client
|
|
47
|
-
*/
|
|
48
|
-
constructor(data, options) {
|
|
49
|
-
super(options);
|
|
50
|
-
Object.defineProperty(this, 'client', { value: this });
|
|
51
|
-
let { id, token } = data;
|
|
52
|
-
|
|
53
|
-
if ('url' in data) {
|
|
54
|
-
const parsed = parseWebhookURL(data.url);
|
|
55
|
-
if (!parsed) {
|
|
56
|
-
throw new DiscordjsError(ErrorCodes.WebhookURLInvalid);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
({ id, token } = parsed);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
this.id = id;
|
|
63
|
-
Object.defineProperty(this, 'token', { value: token, writable: true, configurable: true });
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* The options the webhook client was instantiated with.
|
|
68
|
-
*
|
|
69
|
-
* @type {WebhookClientOptions}
|
|
70
|
-
* @name WebhookClient#options
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
// These are here only for documentation purposes - they are implemented by Webhook
|
|
74
|
-
|
|
75
|
-
/* eslint-disable jsdoc/check-param-names, getter-return */
|
|
76
|
-
/**
|
|
77
|
-
* Sends a message with this webhook.
|
|
78
|
-
*
|
|
79
|
-
* @param {string|MessagePayload|WebhookMessageCreateOptions} options The content for the reply
|
|
80
|
-
* @returns {Promise<APIMessage>}
|
|
81
|
-
*/
|
|
82
|
-
async send() {}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Gets a message that was sent by this webhook.
|
|
86
|
-
*
|
|
87
|
-
* @param {Snowflake} message The id of the message to fetch
|
|
88
|
-
* @param {WebhookFetchMessageOptions} [options] The options to provide to fetch the message.
|
|
89
|
-
* @returns {Promise<APIMessage>} Returns the message sent by this webhook
|
|
90
|
-
*/
|
|
91
|
-
async fetchMessage() {}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Edits a message that was sent by this webhook.
|
|
95
|
-
*
|
|
96
|
-
* @param {MessageResolvable} message The message to edit
|
|
97
|
-
* @param {string|MessagePayload|WebhookMessageEditOptions} options The options to provide
|
|
98
|
-
* @returns {Promise<APIMessage>} Returns the message edited by this webhook
|
|
99
|
-
*/
|
|
100
|
-
async editMessage() {}
|
|
101
|
-
|
|
102
|
-
sendSlackMessage() {}
|
|
103
|
-
|
|
104
|
-
edit() {}
|
|
105
|
-
|
|
106
|
-
delete() {}
|
|
107
|
-
|
|
108
|
-
deleteMessage() {}
|
|
109
|
-
|
|
110
|
-
get createdTimestamp() {}
|
|
111
|
-
|
|
112
|
-
get createdAt() {}
|
|
113
|
-
|
|
114
|
-
get url() {}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
Webhook.applyToClass(WebhookClient);
|
|
118
|
-
|
|
119
|
-
exports.WebhookClient = WebhookClient;
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { basename, flatten } = require('../util/Util.js');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Represents an attachment builder
|
|
7
|
-
*/
|
|
8
|
-
class AttachmentBuilder {
|
|
9
|
-
/**
|
|
10
|
-
* @param {BufferResolvable|Stream} attachment The file
|
|
11
|
-
* @param {AttachmentData} [data] Extra data
|
|
12
|
-
*/
|
|
13
|
-
constructor(attachment, data = {}) {
|
|
14
|
-
/**
|
|
15
|
-
* The file associated with this attachment.
|
|
16
|
-
*
|
|
17
|
-
* @type {BufferResolvable|Stream}
|
|
18
|
-
*/
|
|
19
|
-
this.attachment = attachment;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The name of this attachment
|
|
23
|
-
*
|
|
24
|
-
* @type {?string}
|
|
25
|
-
*/
|
|
26
|
-
this.name = data.name;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* The description of the attachment
|
|
30
|
-
*
|
|
31
|
-
* @type {?string}
|
|
32
|
-
*/
|
|
33
|
-
this.description = data.description;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The title of the attachment
|
|
37
|
-
*
|
|
38
|
-
* @type {?string}
|
|
39
|
-
*/
|
|
40
|
-
this.title = data.title;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* The base64 encoded byte array representing a sampled waveform
|
|
44
|
-
* <info>This is only for voice message attachments.</info>
|
|
45
|
-
*
|
|
46
|
-
* @type {?string}
|
|
47
|
-
*/
|
|
48
|
-
this.waveform = data.waveform;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The duration of the attachment in seconds
|
|
52
|
-
* <info>This is only for voice message attachments.</info>
|
|
53
|
-
*
|
|
54
|
-
* @type {?number}
|
|
55
|
-
*/
|
|
56
|
-
this.duration = data.duration;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Sets the description of this attachment.
|
|
61
|
-
*
|
|
62
|
-
* @param {string} description The description of the file
|
|
63
|
-
* @returns {AttachmentBuilder} This attachment
|
|
64
|
-
*/
|
|
65
|
-
setDescription(description) {
|
|
66
|
-
this.description = description;
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Sets the file of this attachment.
|
|
72
|
-
*
|
|
73
|
-
* @param {BufferResolvable|Stream} attachment The file
|
|
74
|
-
* @returns {AttachmentBuilder} This attachment
|
|
75
|
-
*/
|
|
76
|
-
setFile(attachment) {
|
|
77
|
-
this.attachment = attachment;
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Sets the name of this attachment.
|
|
83
|
-
*
|
|
84
|
-
* @param {string} name The name of the file
|
|
85
|
-
* @returns {AttachmentBuilder} This attachment
|
|
86
|
-
*/
|
|
87
|
-
setName(name) {
|
|
88
|
-
this.name = name;
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Sets the title of this attachment.
|
|
94
|
-
*
|
|
95
|
-
* @param {string} title The title of the file
|
|
96
|
-
* @returns {AttachmentBuilder} This attachment
|
|
97
|
-
*/
|
|
98
|
-
setTitle(title) {
|
|
99
|
-
this.title = title;
|
|
100
|
-
return this;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Sets the waveform of this attachment.
|
|
105
|
-
* <info>This is only for voice message attachments.</info>
|
|
106
|
-
*
|
|
107
|
-
* @param {string} waveform The base64 encoded byte array representing a sampled waveform
|
|
108
|
-
* @returns {AttachmentBuilder} This attachment
|
|
109
|
-
*/
|
|
110
|
-
setWaveform(waveform) {
|
|
111
|
-
this.waveform = waveform;
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Sets the duration of this attachment.
|
|
117
|
-
* <info>This is only for voice message attachments.</info>
|
|
118
|
-
*
|
|
119
|
-
* @param {number} duration The duration of the attachment in seconds
|
|
120
|
-
* @returns {AttachmentBuilder} This attachment
|
|
121
|
-
*/
|
|
122
|
-
setDuration(duration) {
|
|
123
|
-
this.duration = duration;
|
|
124
|
-
return this;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Sets whether this attachment is a spoiler
|
|
129
|
-
*
|
|
130
|
-
* @param {boolean} [spoiler=true] Whether the attachment should be marked as a spoiler
|
|
131
|
-
* @returns {AttachmentBuilder} This attachment
|
|
132
|
-
*/
|
|
133
|
-
setSpoiler(spoiler = true) {
|
|
134
|
-
if (spoiler === this.spoiler) return this;
|
|
135
|
-
|
|
136
|
-
if (!spoiler) {
|
|
137
|
-
while (this.spoiler) {
|
|
138
|
-
this.name = this.name.slice('SPOILER_'.length);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
this.name = `SPOILER_${this.name}`;
|
|
145
|
-
return this;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Whether or not this attachment has been marked as a spoiler
|
|
150
|
-
*
|
|
151
|
-
* @type {boolean}
|
|
152
|
-
* @readonly
|
|
153
|
-
*/
|
|
154
|
-
get spoiler() {
|
|
155
|
-
return basename(this.name).startsWith('SPOILER_');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
toJSON() {
|
|
159
|
-
return flatten(this);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Makes a new builder instance from a preexisting attachment structure.
|
|
164
|
-
*
|
|
165
|
-
* @param {AttachmentBuilder|Attachment|AttachmentPayload} other The builder to construct a new instance from
|
|
166
|
-
* @returns {AttachmentBuilder}
|
|
167
|
-
*/
|
|
168
|
-
static from(other) {
|
|
169
|
-
return new AttachmentBuilder(other.attachment, {
|
|
170
|
-
name: other.name,
|
|
171
|
-
description: other.description,
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
exports.AttachmentBuilder = AttachmentBuilder;
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* @typedef {Object} AttachmentData
|
|
180
|
-
* @property {string} [name] The name of the attachment
|
|
181
|
-
* @property {string} [description] The description of the attachment
|
|
182
|
-
* @property {string} [title] The title of the attachment
|
|
183
|
-
* @property {string} [waveform] The base64 encoded byte array representing a sampled waveform (for voice message attachments)
|
|
184
|
-
* @property {number} [duration] The duration of the attachment in seconds (for voice message attachments)
|
|
185
|
-
*/
|