Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/methods/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ class ChannelMethods {
* @since 0.7.0
* @param channelId The Id of the announcement channel
* @param webhookChannelId The Id of the channel messages will be sent to
* @param reason Reason to show in the audit log
* @returns A [followed channel](https://discord.com/developers/docs/resources/channel#followed-channel-object) object
*
* | Permissions needed | Condition |
Expand All @@ -659,8 +660,8 @@ class ChannelMethods {
* const client = new SnowTransfer("TOKEN")
* client.channel.followAnnouncementChannel("news channel id", "text channel id")
*/
public async followAnnouncementChannel(channelId: string, webhookChannelId: string): Promise<RESTPostAPIChannelFollowersResult> {
return this.requestHandler.request(Endpoints.CHANNEL_FOLLOWERS(channelId), {}, "post", "json", { webhook_channel_id: webhookChannelId });
public async followAnnouncementChannel(channelId: string, webhookChannelId: string, reason?: string): Promise<RESTPostAPIChannelFollowersResult> {
return this.requestHandler.request(Endpoints.CHANNEL_FOLLOWERS(channelId), {}, "post", "json", { webhook_channel_id: webhookChannelId, reason });
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/methods/Guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class GuildMethods {
* }
* client.guild.updateGuild("guild Id", guildData)
*/
public async updateGuild(guildId: string, data: RESTPatchAPIGuildJSONBody): Promise<RESTPatchAPIGuildResult> {
public async updateGuild(guildId: string, data: RESTPatchAPIGuildJSONBody & { reason?: string; }): Promise<RESTPatchAPIGuildResult> {
return this.requestHandler.request(Endpoints.GUILD(guildId), {}, "patch", "json", data);
}

Expand Down Expand Up @@ -191,7 +191,7 @@ class GuildMethods {
* \}
* const channel = await client.guild.createGuildChannel("guild id", channelData)
*/
public async createGuildChannel(guildId: string, data: RESTPostAPIGuildChannelJSONBody): Promise<RESTPostAPIGuildChannelResult> {
public async createGuildChannel(guildId: string, data: RESTPostAPIGuildChannelJSONBody & { reason?: string; }): Promise<RESTPostAPIGuildChannelResult> {
return this.requestHandler.request(Endpoints.GUILD_CHANNELS(guildId), {}, "post", "json", data);
}

Expand Down Expand Up @@ -342,7 +342,7 @@ class GuildMethods {
* }
* const member = await client.guild.updateGuildMember("guild Id", "memberId", memberData)
*/
public async updateGuildMember(guildId: string, memberId: string, data: RESTPatchAPIGuildMemberJSONBody): Promise<RESTPatchAPIGuildMemberResult> {
public async updateGuildMember(guildId: string, memberId: string, data: RESTPatchAPIGuildMemberJSONBody & { reason?: string; }): Promise<RESTPatchAPIGuildMemberResult> {
return this.requestHandler.request(Endpoints.GUILD_MEMBER(guildId, memberId), {}, "patch", "json", data);
}

Expand Down Expand Up @@ -601,7 +601,7 @@ class GuildMethods {
* }
* client.guild.updateGuildRole("guildId", "roleId", roleData)
*/
public async updateGuildRole(guildId: string, roleId: string, data: RESTPatchAPIGuildRoleJSONBody): Promise<RESTPatchAPIGuildRoleResult> {
public async updateGuildRole(guildId: string, roleId: string, data: RESTPatchAPIGuildRoleJSONBody & { reason?: string; }): Promise<RESTPatchAPIGuildRoleResult> {
return this.requestHandler.request(Endpoints.GUILD_ROLE(guildId, roleId), {}, "patch", "json", data);
}

Expand Down
4 changes: 2 additions & 2 deletions src/methods/GuildScheduledEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class GuildScheduledEventMethods {
* }
* const event = await client.guildScheduledEvent.createGuildScheduledEvent(guildId, eventData)
*/
public async createGuildScheduledEvent(guildId: string, data: RESTPostAPIGuildScheduledEventJSONBody): Promise<RESTPostAPIGuildScheduledEventResult> {
public async createGuildScheduledEvent(guildId: string, data: RESTPostAPIGuildScheduledEventJSONBody & { reason?: string; }): Promise<RESTPostAPIGuildScheduledEventResult> {
return this.requestHandler.request(Endpoints.GUILD_SCHEDULED_EVENTS(guildId), {}, "post", "json", data);
}

Expand Down Expand Up @@ -117,7 +117,7 @@ class GuildScheduledEventMethods {
* const client = new SnowTransfer("TOKEN")
* const event = await client.guildScheduledEvent.editGuildScheduledEvent(guildId, eventId, { entity_type: 3, channel_id: null, entity_metadata: { location: "Brazil" }, scheduled_end_time: "2025-01-01T00:00:00.000Z" })
*/
public async editGuildScheduledEvent(guildId: string, eventId: string, data: RESTPatchAPIGuildScheduledEventJSONBody): Promise<RESTPatchAPIGuildScheduledEventResult> {
public async editGuildScheduledEvent(guildId: string, eventId: string, data: RESTPatchAPIGuildScheduledEventJSONBody & { reason?: string; }): Promise<RESTPatchAPIGuildScheduledEventResult> {
return this.requestHandler.request(Endpoints.GUILD_SCHEDULED_EVENT(guildId, eventId), {}, "patch", "json", data);
}

Expand Down
9 changes: 5 additions & 4 deletions src/methods/Invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class InviteMethods {
/**
* Get the invite data on an invite id
* @since 0.1.0
* @param inviteId Id of the invite
* @param inviteId Code of the invite
* @param options Query params for additional metadata fields
* @returns [Invite Object](https://discord.com/developers/docs/resources/invite#invite-object)
*
Expand All @@ -42,7 +42,8 @@ class InviteMethods {
/**
* Delete an invite
* @since 0.1.0
* @param inviteId
* @param inviteId The code of the invite to delete
* @param reason The reason to show in the audit log
* @returns [Invite Object](https://discord.com/developers/docs/resources/invite#invite-object)
*
* | Permissions needed | Condition |
Expand All @@ -54,8 +55,8 @@ class InviteMethods {
* const client = new SnowTransfer("TOKEN")
* const invite = await client.invite.deleteInvite("inviteId")
*/
public async deleteInvite(inviteId: string): Promise<RESTDeleteAPIInviteResult> {
return this.requestHandler.request(Endpoints.INVITES(inviteId), {}, "delete", "json");
public async deleteInvite(inviteId: string, reason?: string): Promise<RESTDeleteAPIInviteResult> {
return this.requestHandler.request(Endpoints.INVITES(inviteId), {}, "delete", "json", { reason });
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/methods/Webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class WebhookMethods {
* }
* const webhook = await client.webhook.createWebhook("channel Id", webhookData)
*/
public async createWebhook(channelId: string, data: RESTPostAPIChannelWebhookJSONBody): Promise<RESTPostAPIChannelWebhookResult> {
public async createWebhook(channelId: string, data: RESTPostAPIChannelWebhookJSONBody & { reason?: string; }): Promise<RESTPostAPIChannelWebhookResult> {
return this.requestHandler.request(Endpoints.CHANNEL_WEBHOOKS(channelId), {}, "post", "json", data);
}

Expand Down Expand Up @@ -166,6 +166,7 @@ class WebhookMethods {
* @since 0.1.0
* @param webhookId Id of the webhook
* @param token Webhook token
* @param reason The reason to show in the audit log
* @returns Resolves the Promise on successful execution
*
* | Permissions needed | Condition |
Expand All @@ -177,9 +178,9 @@ class WebhookMethods {
* const client = new SnowTransfer(); // No token needed if webhook token is provided
* client.webhook.deleteWebhook("webhook Id", "webhook token")
*/
public async deleteWebhook(webhookId: string, token?: string): Promise<RESTDeleteAPIWebhookResult> {
if (token) return this.requestHandler.request(Endpoints.WEBHOOK_TOKEN(webhookId, token), {}, "delete", "json") as RESTDeleteAPIWebhookResult;
return this.requestHandler.request(Endpoints.WEBHOOK(webhookId), {}, "delete", "json") as RESTDeleteAPIWebhookResult;
public async deleteWebhook(webhookId: string, token?: string, reason?: string): Promise<RESTDeleteAPIWebhookResult> {
Copy link
Contributor Author

@Zoddo Zoddo Jun 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking a look at this again after sleeping, I'm not sure that's the best way to handle it here. I added it as a second optional argument to not make a breaking change.

However, you may want to set the reason without setting the token. It's technically possible by passing undefined for the token, but it looks a bit weird.

From a lib API perspective, I was wondering if something like that may be cleaner:

public async deleteWebhook(webhookId: string, token?: string): Promise<RESTDeleteAPIWebhookResult>;
public async deleteWebhook(webhookId: string, data?: {token?: string, reason?: string}): Promise<RESTDeleteAPIWebhookResult>;

That way it's not a breaking change either, and we can support a data object with optional properties (instead of relying to optional method parameters that you may have to set to undefined).

if (token) return this.requestHandler.request(Endpoints.WEBHOOK_TOKEN(webhookId, token), {}, "delete", "json", { reason }) as RESTDeleteAPIWebhookResult;
return this.requestHandler.request(Endpoints.WEBHOOK(webhookId), {}, "delete", "json", { reason }) as RESTDeleteAPIWebhookResult;
}

/**
Expand Down