fix: voiceChannel#states types

This commit is contained in:
MARCROCK22 2024-11-21 01:16:29 -04:00
parent 1abf41170e
commit 7ac9135a3c
9 changed files with 44 additions and 37 deletions

View File

@ -13,7 +13,7 @@ export class ApplicationShorter extends BaseShorter {
* @param applicationId The ID of the application. * @param applicationId The ID of the application.
* @returns The emojis. * @returns The emojis.
*/ */
async listEmojis(applicationId: string) { listEmojis(applicationId: string) {
return this.client.proxy.applications(applicationId).emojis.get(); return this.client.proxy.applications(applicationId).emojis.get();
} }
/** /**
@ -22,7 +22,7 @@ export class ApplicationShorter extends BaseShorter {
* @param emojiId The ID of the emoji. * @param emojiId The ID of the emoji.
* @returns The emoji. * @returns The emoji.
*/ */
async getEmoji(applicationId: string, emojiId: string) { getEmoji(applicationId: string, emojiId: string) {
return this.client.proxy.applications(applicationId).emojis(emojiId).get(); return this.client.proxy.applications(applicationId).emojis(emojiId).get();
} }
@ -33,7 +33,7 @@ export class ApplicationShorter extends BaseShorter {
* @param body.image The [image data string](https://discord.com/developers/docs/reference#image-data) of the emoji. * @param body.image The [image data string](https://discord.com/developers/docs/reference#image-data) of the emoji.
* @returns The created emoji. * @returns The created emoji.
*/ */
async createEmoji(applicationId: string, body: RESTPostAPIApplicationEmojiJSONBody) { createEmoji(applicationId: string, body: RESTPostAPIApplicationEmojiJSONBody) {
return this.client.proxy.applications(applicationId).emojis.post({ body }); return this.client.proxy.applications(applicationId).emojis.post({ body });
} }
@ -42,7 +42,7 @@ export class ApplicationShorter extends BaseShorter {
* @param applicationId The ID of the application. * @param applicationId The ID of the application.
* @param [query] The query parameters. * @param [query] The query parameters.
*/ */
async listEntitlements(applicationId: string, query?: RESTGetAPIEntitlementsQuery) { listEntitlements(applicationId: string, query?: RESTGetAPIEntitlementsQuery) {
return this.client.proxy return this.client.proxy
.applications(applicationId) .applications(applicationId)
.entitlements.get({ query }) .entitlements.get({ query })
@ -54,7 +54,7 @@ export class ApplicationShorter extends BaseShorter {
* @param applicationId The ID of the application. * @param applicationId The ID of the application.
* @param entitlementId The ID of the entitlement. * @param entitlementId The ID of the entitlement.
*/ */
async consumeEntitlement(applicationId: string, entitlementId: string) { consumeEntitlement(applicationId: string, entitlementId: string) {
return this.client.proxy.applications(applicationId).entitlements(entitlementId).consume.post(); return this.client.proxy.applications(applicationId).entitlements(entitlementId).consume.post();
} }
@ -63,7 +63,7 @@ export class ApplicationShorter extends BaseShorter {
* @param applicationId The ID of the application. * @param applicationId The ID of the application.
* @param body The body of the request. * @param body The body of the request.
*/ */
async createTestEntitlement(applicationId: string, body: RESTPostAPIEntitlementBody) { createTestEntitlement(applicationId: string, body: RESTPostAPIEntitlementBody) {
return this.client.proxy return this.client.proxy
.applications(applicationId) .applications(applicationId)
.entitlements.post({ body }) .entitlements.post({ body })
@ -75,7 +75,7 @@ export class ApplicationShorter extends BaseShorter {
* @param applicationId The ID of the application. * @param applicationId The ID of the application.
* @param entitlementId The ID of the entitlement. * @param entitlementId The ID of the entitlement.
*/ */
async deleteTestEntitlement(applicationId: string, entitlementId: string) { deleteTestEntitlement(applicationId: string, entitlementId: string) {
return this.client.proxy.applications(applicationId).entitlements(entitlementId).delete(); return this.client.proxy.applications(applicationId).entitlements(entitlementId).delete();
} }
@ -84,7 +84,7 @@ export class ApplicationShorter extends BaseShorter {
* @param applicationId The ID of the application. * @param applicationId The ID of the application.
* @returns The SKUs. * @returns The SKUs.
*/ */
async listSKUs(applicationId: string) { listSKUs(applicationId: string) {
return this.client.proxy.applications(applicationId).skus.get(); return this.client.proxy.applications(applicationId).skus.get();
} }
} }

View File

@ -26,8 +26,8 @@ export class BanShorter extends BaseShorter {
* @param memberId The ID of the member to unban. * @param memberId The ID of the member to unban.
* @param reason The reason for unbanning the member. * @param reason The reason for unbanning the member.
*/ */
async remove(guildId: string, memberId: string, reason?: string) { remove(guildId: string, memberId: string, reason?: string) {
await this.client.proxy.guilds(guildId).bans(memberId).delete({ reason }); return this.client.proxy.guilds(guildId).bans(memberId).delete({ reason });
} }
/** /**

View File

@ -86,8 +86,8 @@ export class ChannelShorter extends BaseShorter {
* @param id The ID of the channel. * @param id The ID of the channel.
* @returns A Promise that resolves when the typing indicator is successfully sent. * @returns A Promise that resolves when the typing indicator is successfully sent.
*/ */
async typing(id: string): Promise<void> { typing(id: string): Promise<void> {
await this.client.proxy.channels(id).typing.post(); return this.client.proxy.channels(id).typing.post();
} }
async pins(channelId: string): Promise<MessageStructure[]> { async pins(channelId: string): Promise<MessageStructure[]> {
@ -129,7 +129,7 @@ export class ChannelShorter extends BaseShorter {
* @param reason The reason for unpinning the message. * @param reason The reason for unpinning the message.
* @returns A promise that resolves when the thread is succesfully created. * @returns A promise that resolves when the thread is succesfully created.
*/ */
async thread( thread(
channelId: string, channelId: string,
body: RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody, body: RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody,
reason?: string, reason?: string,

View File

@ -65,8 +65,8 @@ export class MemberShorter extends BaseShorter {
* @param memberId The ID of the member to unban. * @param memberId The ID of the member to unban.
* @param reason The reason for unbanning the member. * @param reason The reason for unbanning the member.
*/ */
async unban(guildId: string, memberId: string, reason?: string) { unban(guildId: string, memberId: string, reason?: string) {
await this.client.proxy.guilds(guildId).bans(memberId).delete({ reason }); return this.client.proxy.guilds(guildId).bans(memberId).delete({ reason });
} }
/** /**

View File

@ -103,7 +103,7 @@ export class RoleShorter extends BaseShorter {
}); });
if (!this.client.cache.hasRolesIntent) { if (!this.client.cache.hasRolesIntent) {
await this.client.cache.roles?.set( await this.client.cache.roles?.set(
roles.map(x => [x.id, x]), roles.map(x => [x.id, x] as [string, any]),
guildId, guildId,
); );
} }

View File

@ -20,7 +20,7 @@ export class ThreadShorter extends BaseShorter {
* @param reason The reason for unpinning the message. * @param reason The reason for unpinning the message.
* @returns A promise that resolves when the thread is succesfully created. * @returns A promise that resolves when the thread is succesfully created.
*/ */
async create( create(
channelId: string, channelId: string,
body: RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody, body: RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody,
reason?: string, reason?: string,
@ -42,7 +42,7 @@ export class ThreadShorter extends BaseShorter {
); );
} }
async fromMessage( fromMessage(
channelId: string, channelId: string,
messageId: string, messageId: string,
options: RESTPostAPIChannelMessagesThreadsJSONBody & { reason?: string }, options: RESTPostAPIChannelMessagesThreadsJSONBody & { reason?: string },

View File

@ -68,12 +68,12 @@ export class BaseMessage extends DiscordBase {
return Formatter.messageLink(this.guildId!, this.channelId, this.id); return Formatter.messageLink(this.guildId!, this.channelId, this.id);
} }
guild(force = false) { async guild(force = false) {
if (!this.guildId) return; if (!this.guildId) return;
return this.client.guilds.fetch(this.guildId, force); return this.client.guilds.fetch(this.guildId, force);
} }
async channel(force = false) { channel(force = false) {
return this.client.channels.fetch(this.channelId, force); return this.client.channels.fetch(this.channelId, force);
} }

View File

@ -30,7 +30,7 @@ export class VoiceState extends Base {
return this.client.users.fetch(this.userId, force); return this.client.users.fetch(this.userId, force);
} }
channel(force?: boolean) { async channel(force?: boolean) {
if (!this.channelId) return; if (!this.channelId) return;
return this.client.channels.fetch(this.channelId, force) as Promise<AllGuildVoiceChannels>; return this.client.channels.fetch(this.channelId, force) as Promise<AllGuildVoiceChannels>;
} }

View File

@ -1,4 +1,4 @@
import { Collection, Formatter, type RawFile } from '..'; import { Collection, Formatter, type RawFile, type ReturnCache } from '..';
import { ActionRow, Embed, PollBuilder, resolveAttachment } from '../builders'; import { ActionRow, Embed, PollBuilder, resolveAttachment } from '../builders';
import { import {
type BaseChannelStructure, type BaseChannelStructure,
@ -15,16 +15,18 @@ import {
type ThreadChannelStructure, type ThreadChannelStructure,
Transformers, Transformers,
type VoiceChannelStructure, type VoiceChannelStructure,
type VoiceStateStructure,
} from '../client'; } from '../client';
import type { UsingClient } from '../commands'; import type { UsingClient } from '../commands';
import type { import {
EmojiResolvable, type EmojiResolvable,
MessageCreateBodyRequest, type MessageCreateBodyRequest,
MessageUpdateBodyRequest, type MessageUpdateBodyRequest,
MethodContext, type MethodContext,
ObjectToLower, type ObjectToLower,
StringToNumber, type StringToNumber,
ToClass, type ToClass,
fakePromise,
} from '../common'; } from '../common';
import { mix } from '../deps/mixer'; import { mix } from '../deps/mixer';
import { import {
@ -376,7 +378,7 @@ export class ThreadOnlyMethods extends DiscordBase {
return this.edit({ default_thread_rate_limit_per_user: rate }, reason); return this.edit({ default_thread_rate_limit_per_user: rate }, reason);
} }
async thread(body: RESTPostAPIGuildForumThreadsJSONBody, reason?: string) { thread(body: RESTPostAPIGuildForumThreadsJSONBody, reason?: string) {
return this.client.channels.thread(this.id, body, reason); return this.client.channels.thread(this.id, body, reason);
} }
} }
@ -404,11 +406,16 @@ export class VoiceChannelMethods extends DiscordBase {
return this.client.channels.setVoiceStatus(this.id, status); return this.client.channels.setVoiceStatus(this.id, status);
} }
async states() { states(): ReturnCache<VoiceStateStructure[]> {
if (!this.guildId) return []; if (!this.guildId) return this.cache.adapter.isAsync ? (Promise.resolve([]) as never) : [];
const states = await this.cache.voiceStates?.values(this.guildId); return fakePromise(
if (!states?.length) return []; this.cache.voiceStates?.values(this.guildId) ??
return states.filter(state => state.channelId === this.id); (this.cache.adapter.isAsync
? (Promise.resolve([]) as Promise<VoiceStateStructure[]>)
: ([] as VoiceStateStructure[])),
).then(states => {
return states.filter(state => state.channelId === this.id);
});
} }
public async members(force?: boolean) { public async members(force?: boolean) {
@ -447,7 +454,7 @@ export class WebhookChannelMethods extends DiscordBase {
static channel(ctx: MethodContext<{ channelId: string }>) { static channel(ctx: MethodContext<{ channelId: string }>) {
return { return {
list: () => ctx.client.webhooks.listFromChannel(ctx.channelId), list: () => ctx.client.webhooks.listFromChannel(ctx.channelId),
create: async (body: RESTPostAPIChannelWebhookJSONBody) => ctx.client.webhooks.create(ctx.channelId, body), create: (body: RESTPostAPIChannelWebhookJSONBody) => ctx.client.webhooks.create(ctx.channelId, body),
}; };
} }
} }