@discordjs/core 3.0.0-dev.1738066740-6df42db33 → 3.0.0-dev.1738152304-5f463eb9e
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 +2 -1
- package/dist/http-only.js +1 -1
- package/dist/http-only.js.map +1 -1
- package/dist/http-only.mjs +1 -1
- package/dist/http-only.mjs.map +1 -1
- package/dist/index.d.mts +37 -1
- package/dist/index.d.ts +37 -1
- package/dist/index.js +88 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +88 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -3091,6 +3091,10 @@ import {
|
|
|
3091
3091
|
GatewayDispatchEvents,
|
|
3092
3092
|
GatewayOpcodes
|
|
3093
3093
|
} from "discord-api-types/v10";
|
|
3094
|
+
function createTimer(controller, timeout) {
|
|
3095
|
+
return setTimeout(() => controller.abort(), timeout);
|
|
3096
|
+
}
|
|
3097
|
+
__name(createTimer, "createTimer");
|
|
3094
3098
|
var Client = class extends AsyncEventEmitter {
|
|
3095
3099
|
static {
|
|
3096
3100
|
__name(this, "Client");
|
|
@@ -3125,10 +3129,7 @@ var Client = class extends AsyncEventEmitter {
|
|
|
3125
3129
|
const shardId = calculateShardId(options.guild_id, await this.gateway.getShardCount());
|
|
3126
3130
|
const nonce = options.nonce ?? DiscordSnowflake.generate().toString();
|
|
3127
3131
|
const controller = new AbortController();
|
|
3128
|
-
|
|
3129
|
-
controller.abort();
|
|
3130
|
-
}, timeout), "createTimer");
|
|
3131
|
-
let timer = createTimer();
|
|
3132
|
+
let timer = createTimer(controller, timeout);
|
|
3132
3133
|
await this.gateway.send(shardId, {
|
|
3133
3134
|
op: GatewayOpcodes.RequestGuildMembers,
|
|
3134
3135
|
// eslint-disable-next-line id-length
|
|
@@ -3153,11 +3154,8 @@ var Client = class extends AsyncEventEmitter {
|
|
|
3153
3154
|
chunkIndex: data.chunk_index,
|
|
3154
3155
|
chunkCount: data.chunk_count
|
|
3155
3156
|
};
|
|
3156
|
-
if (data.chunk_index >= data.chunk_count - 1)
|
|
3157
|
-
|
|
3158
|
-
} else {
|
|
3159
|
-
timer = createTimer();
|
|
3160
|
-
}
|
|
3157
|
+
if (data.chunk_index >= data.chunk_count - 1) break;
|
|
3158
|
+
timer = createTimer(controller, timeout);
|
|
3161
3159
|
}
|
|
3162
3160
|
} catch (error) {
|
|
3163
3161
|
if (error instanceof Error && error.name === "AbortError") {
|
|
@@ -3194,6 +3192,86 @@ var Client = class extends AsyncEventEmitter {
|
|
|
3194
3192
|
}
|
|
3195
3193
|
return { members, nonce, notFound, presences };
|
|
3196
3194
|
}
|
|
3195
|
+
/**
|
|
3196
|
+
* Requests soundboard sounds from the gateway and returns an async iterator that yields the data from each soundboard sounds event.
|
|
3197
|
+
*
|
|
3198
|
+
* @see {@link https://discord.com/developers/docs/topics/gateway-events#request-soundboard-sounds}
|
|
3199
|
+
* @param options - The options for the request
|
|
3200
|
+
* @param timeout - The timeout for waiting for each soundboard sounds
|
|
3201
|
+
* @example
|
|
3202
|
+
* Requesting soundboard sounds for specific guilds
|
|
3203
|
+
* ```ts
|
|
3204
|
+
* for await (const { guildId, soundboardSounds } of this.requestSoundboardSoundsIterator({
|
|
3205
|
+
* guild_ids: ['1234567890', '9876543210'],
|
|
3206
|
+
* })) {
|
|
3207
|
+
* console.log(`Soundboard sounds for guild ${guildId}:`, soundboardSounds);
|
|
3208
|
+
* }
|
|
3209
|
+
* ```
|
|
3210
|
+
*/
|
|
3211
|
+
async *requestSoundboardSoundsIterator(options, timeout = 1e4) {
|
|
3212
|
+
const shardCount = await this.gateway.getShardCount();
|
|
3213
|
+
const shardIds = Map.groupBy(options.guild_ids, (guildId) => calculateShardId(guildId, shardCount));
|
|
3214
|
+
const controller = new AbortController();
|
|
3215
|
+
let timer = createTimer(controller, timeout);
|
|
3216
|
+
for (const [shardId, guildIds] of shardIds) {
|
|
3217
|
+
await this.gateway.send(shardId, {
|
|
3218
|
+
op: GatewayOpcodes.RequestSoundboardSounds,
|
|
3219
|
+
// eslint-disable-next-line id-length
|
|
3220
|
+
d: {
|
|
3221
|
+
...options,
|
|
3222
|
+
guild_ids: guildIds
|
|
3223
|
+
}
|
|
3224
|
+
});
|
|
3225
|
+
}
|
|
3226
|
+
try {
|
|
3227
|
+
const iterator = AsyncEventEmitter.on(this, GatewayDispatchEvents.SoundboardSounds, {
|
|
3228
|
+
signal: controller.signal
|
|
3229
|
+
});
|
|
3230
|
+
const guildIds = new Set(options.guild_ids);
|
|
3231
|
+
for await (const [{ data }] of iterator) {
|
|
3232
|
+
if (!guildIds.has(data.guild_id)) continue;
|
|
3233
|
+
clearTimeout(timer);
|
|
3234
|
+
timer = void 0;
|
|
3235
|
+
yield {
|
|
3236
|
+
guildId: data.guild_id,
|
|
3237
|
+
soundboardSounds: data.soundboard_sounds
|
|
3238
|
+
};
|
|
3239
|
+
guildIds.delete(data.guild_id);
|
|
3240
|
+
if (guildIds.size === 0) break;
|
|
3241
|
+
timer = createTimer(controller, timeout);
|
|
3242
|
+
}
|
|
3243
|
+
} catch (error) {
|
|
3244
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
3245
|
+
throw new Error("Request timed out");
|
|
3246
|
+
}
|
|
3247
|
+
throw error;
|
|
3248
|
+
} finally {
|
|
3249
|
+
if (timer) {
|
|
3250
|
+
clearTimeout(timer);
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3253
|
+
}
|
|
3254
|
+
/**
|
|
3255
|
+
* Requests soundboard sounds from the gateway.
|
|
3256
|
+
*
|
|
3257
|
+
* @see {@link https://discord.com/developers/docs/topics/gateway-events#request-soundboard-sounds}
|
|
3258
|
+
* @param options - The options for the request
|
|
3259
|
+
* @param timeout - The timeout for waiting for each soundboard sounds event
|
|
3260
|
+
* @example
|
|
3261
|
+
* Requesting soundboard sounds for specific guilds
|
|
3262
|
+
* ```ts
|
|
3263
|
+
* const soundboardSounds = await client.requestSoundboardSounds({ guild_ids: ['1234567890', '9876543210'], });
|
|
3264
|
+
*
|
|
3265
|
+
* console.log(soundboardSounds.get('1234567890'));
|
|
3266
|
+
* ```
|
|
3267
|
+
*/
|
|
3268
|
+
async requestSoundboardSounds(options, timeout = 1e4) {
|
|
3269
|
+
const soundboardSounds = /* @__PURE__ */ new Map();
|
|
3270
|
+
for await (const data of this.requestSoundboardSoundsIterator(options, timeout)) {
|
|
3271
|
+
soundboardSounds.set(data.guildId, data.soundboardSounds);
|
|
3272
|
+
}
|
|
3273
|
+
return soundboardSounds;
|
|
3274
|
+
}
|
|
3197
3275
|
/**
|
|
3198
3276
|
* Updates the voice state of the bot user
|
|
3199
3277
|
*
|
|
@@ -3249,7 +3327,7 @@ __name(withFiles, "withFiles");
|
|
|
3249
3327
|
|
|
3250
3328
|
// src/index.ts
|
|
3251
3329
|
export * from "discord-api-types/v10";
|
|
3252
|
-
var version = "3.0.0-dev.
|
|
3330
|
+
var version = "3.0.0-dev.1738152304-5f463eb9e";
|
|
3253
3331
|
export {
|
|
3254
3332
|
API,
|
|
3255
3333
|
ApplicationCommandsAPI,
|