From e6f94d409dc66fb40eea13c8d2009c763ef1886f Mon Sep 17 00:00:00 2001 From: MARCROCK22 Date: Sat, 3 Aug 2024 03:26:04 +0000 Subject: [PATCH] fix: socramcode --- src/structures/Guild.ts | 4 ++-- src/structures/GuildEmoji.ts | 2 +- src/structures/GuildRole.ts | 2 +- src/structures/GuildTemplate.ts | 2 +- src/structures/Interaction.ts | 2 +- src/structures/Poll.ts | 13 ++++++++++--- src/structures/Sticker.ts | 8 ++++---- src/structures/VoiceState.ts | 27 ++++++++++++--------------- src/structures/Webhook.ts | 6 +++--- src/structures/channels.ts | 10 +++++----- 10 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/structures/Guild.ts b/src/structures/Guild.ts index 2b595c6..e80e6d1 100644 --- a/src/structures/Guild.ts +++ b/src/structures/Guild.ts @@ -61,10 +61,10 @@ export class Guild extends (BaseGuild as unk } } - fetchOwner(force = false) { + async fetchOwner(force = false) { // For no reason, discord has some guilds without owner... 🤓 if (!this.ownerId) { - return Promise.resolve(null); + return null; } return this.members.fetch(this.ownerId, force); } diff --git a/src/structures/GuildEmoji.ts b/src/structures/GuildEmoji.ts index 80b0228..37c23be 100644 --- a/src/structures/GuildEmoji.ts +++ b/src/structures/GuildEmoji.ts @@ -15,7 +15,7 @@ export class GuildEmoji extends DiscordBase { super(client, { ...data, id: data.id! }); } - guild(force = false) { + async guild(force = false) { if (!this.guildId) return; return this.client.guilds.fetch(this.guildId, force); } diff --git a/src/structures/GuildRole.ts b/src/structures/GuildRole.ts index 6c6e7dc..4254a86 100644 --- a/src/structures/GuildRole.ts +++ b/src/structures/GuildRole.ts @@ -22,7 +22,7 @@ export class GuildRole extends DiscordBase { this.permissions = new PermissionsBitField(BigInt(data.permissions)); } - guild(force = false) { + async guild(force = false) { if (!this.guildId) return; return this.client.guilds.fetch(this.guildId, force); } diff --git a/src/structures/GuildTemplate.ts b/src/structures/GuildTemplate.ts index e788a7e..3842bd8 100644 --- a/src/structures/GuildTemplate.ts +++ b/src/structures/GuildTemplate.ts @@ -15,7 +15,7 @@ export class GuildTemplate extends Base { return this.client.guilds.fetch(this.sourceGuildId, force); } - async fetch() { + fetch() { return this.client.templates.fetch(this.sourceGuildId); } diff --git a/src/structures/Interaction.ts b/src/structures/Interaction.ts index 50fe173..0ad5dfb 100644 --- a/src/structures/Interaction.ts +++ b/src/structures/Interaction.ts @@ -411,7 +411,7 @@ export class Interaction< return this.client.interactions.deleteResponse(this.id, this.token, messageId); } - async followup(body: MessageWebhookCreateBodyRequest) { + followup(body: MessageWebhookCreateBodyRequest) { return this.client.interactions.followup(this.token, body); } } diff --git a/src/structures/Poll.ts b/src/structures/Poll.ts index 070482c..f772ee6 100644 --- a/src/structures/Poll.ts +++ b/src/structures/Poll.ts @@ -4,10 +4,9 @@ import { Base } from './extra/Base'; import type { UsingClient } from '../commands'; import type { ValidAnswerId } from '../api/Routes/channels'; -export interface Poll extends ObjectToLower> {} +export interface Poll extends ObjectToLower {} export class Poll extends Base { - expiry: number; constructor( client: UsingClient, data: APIPoll, @@ -15,9 +14,17 @@ export class Poll extends Base { readonly messageId: string, ) { super(client); - this.expiry = Date.parse(data.expiry); Object.assign(this, toCamelCase(data)); } + + get expiryTimestamp() { + return Date.parse(this.expiry); + } + + get expiryAt() { + return new Date(this.expiry); + } + end() { return this.client.messages.endPoll(this.channelId, this.messageId); } diff --git a/src/structures/Sticker.ts b/src/structures/Sticker.ts index d36d216..8469514 100644 --- a/src/structures/Sticker.ts +++ b/src/structures/Sticker.ts @@ -16,22 +16,22 @@ export class Sticker extends DiscordBase { } } - guild(force = false) { + async guild(force = false) { if (!this.guildId) return; return this.client.guilds.fetch(this.id, force); } - edit(body: RESTPatchAPIGuildStickerJSONBody, reason?: string) { + async edit(body: RESTPatchAPIGuildStickerJSONBody, reason?: string) { if (!this.guildId) return; return this.client.guilds.stickers.edit(this.guildId, this.id, body, reason); } - fetch(force = false) { + async fetch(force = false) { if (!this.guildId) return; return this.client.guilds.stickers.fetch(this.guildId, this.id, force); } - delete(reason?: string) { + async delete(reason?: string) { if (!this.guildId) return; return this.client.guilds.stickers.delete(this.guildId, this.id, reason); } diff --git a/src/structures/VoiceState.ts b/src/structures/VoiceState.ts index de52e31..788bb6a 100644 --- a/src/structures/VoiceState.ts +++ b/src/structures/VoiceState.ts @@ -17,7 +17,7 @@ export class VoiceState extends Base { this.withMember = Transformers.GuildMember(client, member, member.user, data.guild_id); } - isMuted() { + get isMuted() { return this.mute || this.selfMute; } @@ -25,7 +25,7 @@ export class VoiceState extends Base { return (this.withMember = await this.client.members.fetch(this.guildId, this.userId, force)); } - async user(force?: boolean) { + user(force?: boolean) { return this.client.users.fetch(this.userId, force); } @@ -35,17 +35,15 @@ export class VoiceState extends Base { } async setMute(mute = !this.mute, reason?: string) { - return this.client.members.edit(this.guildId, this.userId, { mute }, reason).then(member => { - this.mute = mute; - return member; - }); + const member = await this.client.members.edit(this.guildId, this.userId, { mute }, reason); + this.mute = mute; + return member; } async setDeaf(deaf = !this.deaf, reason?: string) { - return this.client.members.edit(this.guildId, this.userId, { deaf }, reason).then(member => { - this.deaf = deaf; - return member; - }); + const member = await this.client.members.edit(this.guildId, this.userId, { deaf }, reason); + this.deaf = deaf; + return member; } async setSuppress(suppress = !this.suppress) { @@ -66,14 +64,13 @@ export class VoiceState extends Base { this.requestToSpeakTimestamp = date; } - async disconnect(reason?: string) { + disconnect(reason?: string) { return this.setChannel(null, reason); } async setChannel(channel_id: null | string, reason?: string) { - return this.client.members.edit(this.guildId, this.userId, { channel_id }, reason).then(member => { - this.channelId = channel_id; - return member; - }); + const member = await this.client.members.edit(this.guildId, this.userId, { channel_id }, reason); + this.channelId = channel_id; + return member; } } diff --git a/src/structures/Webhook.ts b/src/structures/Webhook.ts index 64557f8..9acb42d 100644 --- a/src/structures/Webhook.ts +++ b/src/structures/Webhook.ts @@ -58,7 +58,7 @@ export class Webhook extends DiscordBase { * @param force Whether to force fetching the guild even if it's already cached. * @returns A promise that resolves to the guild associated with the webhook, or undefined if not applicable. */ - guild(force = false) { + async guild(force = false) { if (!this.sourceGuild?.id) return; return this.client.guilds.fetch(this.sourceGuild.id, force); } @@ -90,7 +90,7 @@ export class Webhook extends DiscordBase { * Fetches the webhook data from the Discord API. * @returns A promise that resolves to the fetched webhook data. */ - async fetch() { + fetch() { return this.client.webhooks.fetch(this.id, this.token); } @@ -100,7 +100,7 @@ export class Webhook extends DiscordBase { * @param reason The reason for editing the webhook. * @returns A promise that resolves when the webhook is successfully edited. */ - async edit(body: RESTPatchAPIWebhookJSONBody | RESTPatchAPIWebhookWithTokenJSONBody, reason?: string) { + edit(body: RESTPatchAPIWebhookJSONBody | RESTPatchAPIWebhookWithTokenJSONBody, reason?: string) { return this.client.webhooks.edit(this.id, body, { reason, token: this.token }); } diff --git a/src/structures/channels.ts b/src/structures/channels.ts index 56b1468..3e7caf5 100644 --- a/src/structures/channels.ts +++ b/src/structures/channels.ts @@ -280,7 +280,7 @@ export class MessagesMethods extends DiscordBase { self: UsingClient, ) { const poll = (body as MessageCreateBodyRequest).poll; - const allow = { + const payload = { allowed_mentions: self.options?.allowedMentions, ...body, components: body.components?.map(x => (x instanceof ActionRow ? x.toJSON() : x)) ?? undefined, @@ -288,19 +288,19 @@ export class MessagesMethods extends DiscordBase { poll: poll ? (poll instanceof PollBuilder ? poll.toJSON() : poll) : undefined, }; - if ('attachment' in body) { - allow.attachments = + if ('attachments' in body) { + payload.attachments = body.attachments?.map((x, i) => ({ id: i, ...resolveAttachment(x), })) ?? undefined; } else if (files?.length) { - allow.attachments = files?.map((x, id) => ({ + payload.attachments = files?.map((x, id) => ({ id, filename: x.name, })) as RESTAPIAttachment[]; } - return allow as unknown as T; + return payload as T; } }