Skip to content

Commit d25ef43

Browse files
sdanialrazaJiralite
authored andcommitted
feat: add soundboard (#10536)
* feat: add soundboard * chore: disable `jsdoc/check-param-names` rule * fix: export `SoundboardSoundsAPI`
1 parent 2deea25 commit d25ef43

File tree

5 files changed

+149
-0
lines changed

5 files changed

+149
-0
lines changed

packages/core/src/api/channel.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import {
3434
type RESTPutAPIChannelPermissionJSONBody,
3535
type RESTPutAPIChannelRecipientJSONBody,
3636
type Snowflake,
37+
type RESTPostAPISoundboardSendSoundJSONBody,
38+
type RESTPostAPISendSoundboardSoundResult,
3739
} from 'discord-api-types/v10';
3840

3941
export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody {
@@ -595,6 +597,25 @@ export class ChannelsAPI {
595597
});
596598
}
597599

600+
/**
601+
* Sends a soundboard sound in a channel
602+
*
603+
* @see {@link https://discord.com/developers/docs/resources/soundboard#send-soundboard-sound}
604+
* @param channelId - The id of the channel to send the soundboard sound in
605+
* @param body - The data for sending the soundboard sound
606+
* @param options - The options for sending the soundboard sound
607+
*/
608+
public async sendSoundboardSound(
609+
channelId: Snowflake,
610+
body: RESTPostAPISoundboardSendSoundJSONBody,
611+
{ signal }: Pick<RequestData, 'signal'> = {},
612+
) {
613+
return this.rest.post(Routes.sendSoundboardSound(channelId), {
614+
body,
615+
signal,
616+
}) as Promise<RESTPostAPISendSoundboardSoundResult>;
617+
}
618+
598619
/**
599620
* Adds a recipient to a group DM channel
600621
*

packages/core/src/api/guild.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ import {
102102
type RESTPutAPIGuildOnboardingJSONBody,
103103
type RESTPutAPIGuildOnboardingResult,
104104
type RESTPutAPIGuildTemplateSyncResult,
105+
type RESTGetAPIGuildSoundboardSoundResult,
106+
type RESTGetAPIGuildSoundboardSoundsResult,
107+
type RESTPatchAPIGuildSoundboardSoundJSONBody,
108+
type RESTPatchAPIGuildSoundboardSoundResult,
109+
type RESTPostAPIGuildSoundboardSoundJSONBody,
110+
type RESTPostAPIGuildSoundboardSoundResult,
105111
type Snowflake,
106112
} from 'discord-api-types/v10';
107113
import { VoiceAPI } from './voice';
@@ -1362,6 +1368,95 @@ export class GuildsAPI {
13621368
}) as Promise<RESTPutAPIGuildOnboardingResult>;
13631369
}
13641370

1371+
/**
1372+
* Fetches all the soundboard sounds for a guild
1373+
*
1374+
* @see {@link https://discord.com/developers/docs/resources/soundboard#list-guild-soundboard-sounds}
1375+
* @param guildId - The id of the guild to fetch the soundboard sounds for
1376+
* @param options - The options for fetching the soundboard sounds
1377+
*/
1378+
public async getSoundboardSounds(guildId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
1379+
return this.rest.get(Routes.guildSoundboardSounds(guildId), {
1380+
signal,
1381+
}) as Promise<RESTGetAPIGuildSoundboardSoundsResult>;
1382+
}
1383+
1384+
/**
1385+
* Fetches a soundboard sound for a guild
1386+
*
1387+
* @see {@link https://discord.com/developers/docs/resources/soundboard#get-guild-soundboard-sound}
1388+
* @param guildId - The id of the guild to fetch the soundboard sound for
1389+
* @param soundId - The id of the soundboard sound to fetch
1390+
* @param options - The options for fetching the soundboard sound
1391+
*/
1392+
public async getSoundboardSound(
1393+
guildId: Snowflake,
1394+
soundId: Snowflake,
1395+
{ signal }: Pick<RequestData, 'signal'> = {},
1396+
) {
1397+
return this.rest.get(Routes.guildSoundboardSound(guildId, soundId), {
1398+
signal,
1399+
}) as Promise<RESTGetAPIGuildSoundboardSoundResult>;
1400+
}
1401+
1402+
/**
1403+
* Creates a new soundboard sound for a guild
1404+
*
1405+
* @see {@link https://discord.com/developers/docs/resources/soundboard#create-guild-soundboard-sound}
1406+
* @param guildId - The id of the guild to create the soundboard sound for
1407+
* @param body - The data for creating the soundboard sound
1408+
* @param options - The options for creating the soundboard sound
1409+
*/
1410+
public async createSoundboardSound(
1411+
guildId: Snowflake,
1412+
body: RESTPostAPIGuildSoundboardSoundJSONBody,
1413+
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
1414+
) {
1415+
return this.rest.post(Routes.guildSoundboardSounds(guildId), {
1416+
body,
1417+
reason,
1418+
signal,
1419+
}) as Promise<RESTPostAPIGuildSoundboardSoundResult>;
1420+
}
1421+
1422+
/**
1423+
* Edits a soundboard sound for a guild
1424+
*
1425+
* @see {@link https://discord.com/developers/docs/resources/soundboard#modify-guild-soundboard-sound}
1426+
* @param guildId - The id of the guild to edit the soundboard sound for
1427+
* @param soundId - The id of the soundboard sound to edit
1428+
* @param body - The data for editing the soundboard sound
1429+
* @param options - The options for editing the soundboard sound
1430+
*/
1431+
public async editSoundboardSound(
1432+
guildId: Snowflake,
1433+
soundId: Snowflake,
1434+
body: RESTPatchAPIGuildSoundboardSoundJSONBody,
1435+
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
1436+
) {
1437+
return this.rest.patch(Routes.guildSoundboardSound(guildId, soundId), {
1438+
body,
1439+
reason,
1440+
signal,
1441+
}) as Promise<RESTPatchAPIGuildSoundboardSoundResult>;
1442+
}
1443+
1444+
/**
1445+
* Deletes a soundboard sound for a guild
1446+
*
1447+
* @see {@link https://discord.com/developers/docs/resources/soundboard#delete-guild-soundboard-sound}
1448+
* @param guildId - The id of the guild to delete the soundboard sound for
1449+
* @param soundId - The id of the soundboard sound to delete
1450+
* @param options - The options for deleting the soundboard sound
1451+
*/
1452+
public async deleteSoundboardSound(
1453+
guildId: Snowflake,
1454+
soundId: Snowflake,
1455+
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
1456+
) {
1457+
await this.rest.delete(Routes.guildSoundboardSound(guildId, soundId), { reason, signal });
1458+
}
1459+
13651460
/**
13661461
* Modifies incident actions for a guild.
13671462
*

packages/core/src/api/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { MonetizationAPI } from './monetization.js';
1010
import { OAuth2API } from './oauth2.js';
1111
import { PollAPI } from './poll.js';
1212
import { RoleConnectionsAPI } from './roleConnections.js';
13+
import { SoundboardSoundsAPI } from './soundboardSounds.js';
1314
import { StageInstancesAPI } from './stageInstances.js';
1415
import { StickersAPI } from './sticker.js';
1516
import { ThreadsAPI } from './thread.js';
@@ -28,6 +29,7 @@ export * from './monetization.js';
2829
export * from './oauth2.js';
2930
export * from './poll.js';
3031
export * from './roleConnections.js';
32+
export * from './soundboardSounds.js';
3133
export * from './stageInstances.js';
3234
export * from './sticker.js';
3335
export * from './thread.js';
@@ -58,6 +60,8 @@ export class API {
5860

5961
public readonly roleConnections: RoleConnectionsAPI;
6062

63+
public readonly soundboardSounds: SoundboardSoundsAPI;
64+
6165
public readonly stageInstances: StageInstancesAPI;
6266

6367
public readonly stickers: StickersAPI;
@@ -81,6 +85,7 @@ export class API {
8185
this.oauth2 = new OAuth2API(rest);
8286
this.poll = new PollAPI(rest);
8387
this.roleConnections = new RoleConnectionsAPI(rest);
88+
this.soundboardSounds = new SoundboardSoundsAPI(rest);
8489
this.stageInstances = new StageInstancesAPI(rest);
8590
this.stickers = new StickersAPI(rest);
8691
this.threads = new ThreadsAPI(rest);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable jsdoc/check-param-names */
2+
3+
import type { RequestData, REST } from '@discordjs/rest';
4+
import { Routes, type RESTGetAPISoundboardDefaultSoundsResult } from 'discord-api-types/v10';
5+
6+
export class SoundboardSoundsAPI {
7+
public constructor(private readonly rest: REST) {}
8+
9+
/**
10+
* Fetches all the soundboard default sounds.
11+
*
12+
* @see {@link https://discord.com/developers/docs/resources/soundboard#list-default-soundboard-sounds}
13+
* @param options - The options for fetching the soundboard default sounds.
14+
*/
15+
public async getSoundboardDefaultSounds({ signal }: Pick<RequestData, 'signal'> = {}) {
16+
return this.rest.get(Routes.soundboardDefaultSounds(), {
17+
signal,
18+
}) as Promise<RESTGetAPISoundboardDefaultSoundsResult>;
19+
}
20+
}

packages/core/src/client.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ import {
3838
type GatewayGuildScheduledEventUpdateDispatchData,
3939
type GatewayGuildScheduledEventUserAddDispatchData,
4040
type GatewayGuildScheduledEventUserRemoveDispatchData,
41+
type GatewayGuildSoundboardSoundCreateDispatch,
42+
type GatewayGuildSoundboardSoundDeleteDispatch,
43+
type GatewayGuildSoundboardSoundUpdateDispatch,
44+
type GatewayGuildSoundboardSoundsUpdateDispatch,
4145
type GatewayGuildStickersUpdateDispatchData,
4246
type GatewayGuildUpdateDispatchData,
4347
type GatewayIntegrationCreateDispatchData,
@@ -135,6 +139,10 @@ export interface MappedEvents {
135139
[GatewayDispatchEvents.GuildScheduledEventUserRemove]: [
136140
ToEventProps<GatewayGuildScheduledEventUserRemoveDispatchData>,
137141
];
142+
[GatewayDispatchEvents.GuildSoundboardSoundCreate]: [ToEventProps<GatewayGuildSoundboardSoundCreateDispatch>];
143+
[GatewayDispatchEvents.GuildSoundboardSoundDelete]: [ToEventProps<GatewayGuildSoundboardSoundDeleteDispatch>];
144+
[GatewayDispatchEvents.GuildSoundboardSoundUpdate]: [ToEventProps<GatewayGuildSoundboardSoundUpdateDispatch>];
145+
[GatewayDispatchEvents.GuildSoundboardSoundsUpdate]: [ToEventProps<GatewayGuildSoundboardSoundsUpdateDispatch>];
138146
[GatewayDispatchEvents.GuildStickersUpdate]: [ToEventProps<GatewayGuildStickersUpdateDispatchData>];
139147
[GatewayDispatchEvents.GuildUpdate]: [ToEventProps<GatewayGuildUpdateDispatchData>];
140148
[GatewayDispatchEvents.IntegrationCreate]: [ToEventProps<GatewayIntegrationCreateDispatchData>];

0 commit comments

Comments
 (0)