fix: voiceChannel#states types (#300)

This commit is contained in:
MARCROCK22 2024-11-21 11:48:43 -04:00 committed by GitHub
parent 1abf41170e
commit 621840d1aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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.
* @returns The emojis.
*/
async listEmojis(applicationId: string) {
listEmojis(applicationId: string) {
return this.client.proxy.applications(applicationId).emojis.get();
}
/**
@ -22,7 +22,7 @@ export class ApplicationShorter extends BaseShorter {
* @param emojiId The ID of 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();
}
@ -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.
* @returns The created emoji.
*/
async createEmoji(applicationId: string, body: RESTPostAPIApplicationEmojiJSONBody) {
createEmoji(applicationId: string, body: RESTPostAPIApplicationEmojiJSONBody) {
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 [query] The query parameters.
*/
async listEntitlements(applicationId: string, query?: RESTGetAPIEntitlementsQuery) {
listEntitlements(applicationId: string, query?: RESTGetAPIEntitlementsQuery) {
return this.client.proxy
.applications(applicationId)
.entitlements.get({ query })
@ -54,7 +54,7 @@ export class ApplicationShorter extends BaseShorter {
* @param applicationId The ID of the application.
* @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();
}
@ -63,7 +63,7 @@ export class ApplicationShorter extends BaseShorter {
* @param applicationId The ID of the application.
* @param body The body of the request.
*/
async createTestEntitlement(applicationId: string, body: RESTPostAPIEntitlementBody) {
createTestEntitlement(applicationId: string, body: RESTPostAPIEntitlementBody) {
return this.client.proxy
.applications(applicationId)
.entitlements.post({ body })
@ -75,7 +75,7 @@ export class ApplicationShorter extends BaseShorter {
* @param applicationId The ID of the application.
* @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();
}
@ -84,7 +84,7 @@ export class ApplicationShorter extends BaseShorter {
* @param applicationId The ID of the application.
* @returns The SKUs.
*/
async listSKUs(applicationId: string) {
listSKUs(applicationId: string) {
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 reason The reason for unbanning the member.
*/
async remove(guildId: string, memberId: string, reason?: string) {
await this.client.proxy.guilds(guildId).bans(memberId).delete({ reason });
remove(guildId: string, memberId: string, reason?: string) {
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.
* @returns A Promise that resolves when the typing indicator is successfully sent.
*/
async typing(id: string): Promise<void> {
await this.client.proxy.channels(id).typing.post();
typing(id: string): Promise<void> {
return this.client.proxy.channels(id).typing.post();
}
async pins(channelId: string): Promise<MessageStructure[]> {
@ -129,7 +129,7 @@ export class ChannelShorter extends BaseShorter {
* @param reason The reason for unpinning the message.
* @returns A promise that resolves when the thread is succesfully created.
*/
async thread(
thread(
channelId: string,
body: RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody,
reason?: string,

View File

@ -65,8 +65,8 @@ export class MemberShorter extends BaseShorter {
* @param memberId The ID of the member to unban.
* @param reason The reason for unbanning the member.
*/
async unban(guildId: string, memberId: string, reason?: string) {
await this.client.proxy.guilds(guildId).bans(memberId).delete({ reason });
unban(guildId: string, memberId: string, reason?: string) {
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) {
await this.client.cache.roles?.set(
roles.map(x => [x.id, x]),
roles.map(x => [x.id, x] as [string, any]),
guildId,
);
}

View File

@ -20,7 +20,7 @@ export class ThreadShorter extends BaseShorter {
* @param reason The reason for unpinning the message.
* @returns A promise that resolves when the thread is succesfully created.
*/
async create(
create(
channelId: string,
body: RESTPostAPIChannelThreadsJSONBody | RESTPostAPIGuildForumThreadsJSONBody,
reason?: string,
@ -42,7 +42,7 @@ export class ThreadShorter extends BaseShorter {
);
}
async fromMessage(
fromMessage(
channelId: string,
messageId: 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);
}
guild(force = false) {
async guild(force = false) {
if (!this.guildId) return;
return this.client.guilds.fetch(this.guildId, force);
}
async channel(force = false) {
channel(force = false) {
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);
}
channel(force?: boolean) {
async channel(force?: boolean) {
if (!this.channelId) return;
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 {
type BaseChannelStructure,
@ -15,16 +15,18 @@ import {
type ThreadChannelStructure,
Transformers,
type VoiceChannelStructure,
type VoiceStateStructure,
} from '../client';
import type { UsingClient } from '../commands';
import type {
EmojiResolvable,
MessageCreateBodyRequest,
MessageUpdateBodyRequest,
MethodContext,
ObjectToLower,
StringToNumber,
ToClass,
import {
type EmojiResolvable,
type MessageCreateBodyRequest,
type MessageUpdateBodyRequest,
type MethodContext,
type ObjectToLower,
type StringToNumber,
type ToClass,
fakePromise,
} from '../common';
import { mix } from '../deps/mixer';
import {
@ -376,7 +378,7 @@ export class ThreadOnlyMethods extends DiscordBase {
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);
}
}
@ -404,11 +406,16 @@ export class VoiceChannelMethods extends DiscordBase {
return this.client.channels.setVoiceStatus(this.id, status);
}
async states() {
if (!this.guildId) return [];
const states = await this.cache.voiceStates?.values(this.guildId);
if (!states?.length) return [];
return states.filter(state => state.channelId === this.id);
states(): ReturnCache<VoiceStateStructure[]> {
if (!this.guildId) return this.cache.adapter.isAsync ? (Promise.resolve([]) as never) : [];
return fakePromise(
this.cache.voiceStates?.values(this.guildId) ??
(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) {
@ -447,7 +454,7 @@ export class WebhookChannelMethods extends DiscordBase {
static channel(ctx: MethodContext<{ channelId: string }>) {
return {
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),
};
}
}