This commit is contained in:
MARCROCK22 2024-03-18 19:40:31 -04:00
parent 870e18a056
commit 6d47f6ee17
2 changed files with 20 additions and 15 deletions

View File

@ -1,6 +1,7 @@
import type {
RESTPatchAPIWebhookJSONBody,
RESTPatchAPIWebhookWithTokenJSONBody,
RESTPostAPIChannelWebhookJSONBody,
RESTPostAPIWebhookWithTokenJSONBody,
} from '..';
import { resolveFiles } from '../../builders';
@ -14,6 +15,12 @@ import {
import { BaseShorter } from './base';
export class WebhookShorter extends BaseShorter {
async create(channelId: string, body: RESTPostAPIChannelWebhookJSONBody) {
const webhook = await this.client.proxy.channels(channelId).webhooks.post({
body,
});
return new Webhook(this.client, webhook);
}
/**
* Deletes a webhook.
* @param webhookId The ID of the webhook.
@ -128,6 +135,16 @@ export class WebhookShorter extends BaseShorter {
.get({ auth: false, query: { threadId } });
return message ? new WebhookMessage(this.client, message, webhookId, token) : undefined;
}
async listFromGuild(guildId: string) {
const webhooks = await this.client.proxy.guilds(guildId).webhooks.get();
return webhooks.map(webhook => new Webhook(this.client, webhook));
}
async listFromChannel(channelId: string) {
const webhooks = await this.client.proxy.channels(channelId).webhooks.get();
return webhooks.map(webhook => new Webhook(this.client, webhook));
}
}
export type WebhookShorterOptionalParams = Partial<{ token: string; reason: string }>;

View File

@ -37,7 +37,6 @@ import type {
} from '../common';
import type { GuildMember } from './GuildMember';
import type { GuildRole } from './GuildRole';
import { Webhook } from './Webhook';
import { DiscordBase } from './extra/DiscordBase';
import { channelLink } from './extra/functions';
@ -353,10 +352,7 @@ export class WebhookGuildMethods extends DiscordBase {
static guild(ctx: MethodContext<{ guildId: string }>) {
return {
list: async () => {
const webhooks = await ctx.client.proxy.guilds(ctx.guildId).webhooks.get();
return webhooks.map(webhook => new Webhook(ctx.client, webhook));
},
list: () => ctx.client.webhooks.listFromChannel(ctx.guildId),
};
}
}
@ -366,16 +362,8 @@ export class WebhookChannelMethods extends DiscordBase {
static channel(ctx: MethodContext<{ channelId: string }>) {
return {
list: async () => {
const webhooks = await ctx.client.proxy.channels(ctx.channelId).webhooks.get();
return webhooks.map(webhook => new Webhook(ctx.client, webhook));
},
create: async (body: RESTPostAPIChannelWebhookJSONBody) => {
const webhook = await ctx.client.proxy.channels(ctx.channelId).webhooks.post({
body,
});
return new Webhook(ctx.client, webhook);
},
list: () => ctx.client.webhooks.listFromChannel(ctx.channelId),
create: async (body: RESTPostAPIChannelWebhookJSONBody) => ctx.client.webhooks.create(ctx.channelId, body),
};
}
}