Skip to content

Commit a9f629b

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

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
@@ -33,6 +33,8 @@ import {
3333
type RESTPostAPIChannelThreadsResult,
3434
type APIThreadChannel,
3535
type RESTPostAPIGuildForumThreadsJSONBody,
36+
type RESTPostAPISoundboardSendSoundJSONBody,
37+
type RESTPostAPISendSoundboardSoundResult,
3638
} from 'discord-api-types/v10';
3739

3840
export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody {
@@ -583,4 +585,23 @@ export class ChannelsAPI {
583585
signal,
584586
});
585587
}
588+
589+
/**
590+
* Sends a soundboard sound in a channel
591+
*
592+
* @see {@link https://discord.com/developers/docs/resources/soundboard#send-soundboard-sound}
593+
* @param channelId - The id of the channel to send the soundboard sound in
594+
* @param body - The data for sending the soundboard sound
595+
* @param options - The options for sending the soundboard sound
596+
*/
597+
public async sendSoundboardSound(
598+
channelId: Snowflake,
599+
body: RESTPostAPISoundboardSendSoundJSONBody,
600+
{ signal }: Pick<RequestData, 'signal'> = {},
601+
) {
602+
return this.rest.post(Routes.sendSoundboardSound(channelId), {
603+
body,
604+
signal,
605+
}) as Promise<RESTPostAPISendSoundboardSoundResult>;
606+
}
586607
}

packages/core/src/api/guild.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ import {
100100
type RESTPutAPIGuildOnboardingJSONBody,
101101
type RESTPutAPIGuildOnboardingResult,
102102
type RESTPutAPIGuildTemplateSyncResult,
103+
type RESTGetAPIGuildSoundboardSoundResult,
104+
type RESTGetAPIGuildSoundboardSoundsResult,
105+
type RESTPatchAPIGuildSoundboardSoundJSONBody,
106+
type RESTPatchAPIGuildSoundboardSoundResult,
107+
type RESTPostAPIGuildSoundboardSoundJSONBody,
108+
type RESTPostAPIGuildSoundboardSoundResult,
103109
type Snowflake,
104110
} from 'discord-api-types/v10';
105111
import { VoiceAPI } from './voice';
@@ -1356,4 +1362,93 @@ export class GuildsAPI {
13561362
signal,
13571363
}) as Promise<RESTPutAPIGuildOnboardingResult>;
13581364
}
1365+
1366+
/**
1367+
* Fetches all the soundboard sounds for a guild
1368+
*
1369+
* @see {@link https://discord.com/developers/docs/resources/soundboard#list-guild-soundboard-sounds}
1370+
* @param guildId - The id of the guild to fetch the soundboard sounds for
1371+
* @param options - The options for fetching the soundboard sounds
1372+
*/
1373+
public async getSoundboardSounds(guildId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
1374+
return this.rest.get(Routes.guildSoundboardSounds(guildId), {
1375+
signal,
1376+
}) as Promise<RESTGetAPIGuildSoundboardSoundsResult>;
1377+
}
1378+
1379+
/**
1380+
* Fetches a soundboard sound for a guild
1381+
*
1382+
* @see {@link https://discord.com/developers/docs/resources/soundboard#get-guild-soundboard-sound}
1383+
* @param guildId - The id of the guild to fetch the soundboard sound for
1384+
* @param soundId - The id of the soundboard sound to fetch
1385+
* @param options - The options for fetching the soundboard sound
1386+
*/
1387+
public async getSoundboardSound(
1388+
guildId: Snowflake,
1389+
soundId: Snowflake,
1390+
{ signal }: Pick<RequestData, 'signal'> = {},
1391+
) {
1392+
return this.rest.get(Routes.guildSoundboardSound(guildId, soundId), {
1393+
signal,
1394+
}) as Promise<RESTGetAPIGuildSoundboardSoundResult>;
1395+
}
1396+
1397+
/**
1398+
* Creates a new soundboard sound for a guild
1399+
*
1400+
* @see {@link https://discord.com/developers/docs/resources/soundboard#create-guild-soundboard-sound}
1401+
* @param guildId - The id of the guild to create the soundboard sound for
1402+
* @param body - The data for creating the soundboard sound
1403+
* @param options - The options for creating the soundboard sound
1404+
*/
1405+
public async createSoundboardSound(
1406+
guildId: Snowflake,
1407+
body: RESTPostAPIGuildSoundboardSoundJSONBody,
1408+
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
1409+
) {
1410+
return this.rest.post(Routes.guildSoundboardSounds(guildId), {
1411+
body,
1412+
reason,
1413+
signal,
1414+
}) as Promise<RESTPostAPIGuildSoundboardSoundResult>;
1415+
}
1416+
1417+
/**
1418+
* Edits a soundboard sound for a guild
1419+
*
1420+
* @see {@link https://discord.com/developers/docs/resources/soundboard#modify-guild-soundboard-sound}
1421+
* @param guildId - The id of the guild to edit the soundboard sound for
1422+
* @param soundId - The id of the soundboard sound to edit
1423+
* @param body - The data for editing the soundboard sound
1424+
* @param options - The options for editing the soundboard sound
1425+
*/
1426+
public async editSoundboardSound(
1427+
guildId: Snowflake,
1428+
soundId: Snowflake,
1429+
body: RESTPatchAPIGuildSoundboardSoundJSONBody,
1430+
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
1431+
) {
1432+
return this.rest.patch(Routes.guildSoundboardSound(guildId, soundId), {
1433+
body,
1434+
reason,
1435+
signal,
1436+
}) as Promise<RESTPatchAPIGuildSoundboardSoundResult>;
1437+
}
1438+
1439+
/**
1440+
* Deletes a soundboard sound for a guild
1441+
*
1442+
* @see {@link https://discord.com/developers/docs/resources/soundboard#delete-guild-soundboard-sound}
1443+
* @param guildId - The id of the guild to delete the soundboard sound for
1444+
* @param soundId - The id of the soundboard sound to delete
1445+
* @param options - The options for deleting the soundboard sound
1446+
*/
1447+
public async deleteSoundboardSound(
1448+
guildId: Snowflake,
1449+
soundId: Snowflake,
1450+
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
1451+
) {
1452+
await this.rest.delete(Routes.guildSoundboardSound(guildId, soundId), { reason, signal });
1453+
}
13591454
}

packages/core/src/api/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { MonetizationAPI } from './monetization.js';
99
import { OAuth2API } from './oauth2.js';
1010
import { PollAPI } from './poll.js';
1111
import { RoleConnectionsAPI } from './roleConnections.js';
12+
import { SoundboardSoundsAPI } from './soundboardSounds.js';
1213
import { StageInstancesAPI } from './stageInstances.js';
1314
import { StickersAPI } from './sticker.js';
1415
import { ThreadsAPI } from './thread.js';
@@ -26,6 +27,7 @@ export * from './monetization.js';
2627
export * from './oauth2.js';
2728
export * from './poll.js';
2829
export * from './roleConnections.js';
30+
export * from './soundboardSounds.js';
2931
export * from './stageInstances.js';
3032
export * from './sticker.js';
3133
export * from './thread.js';
@@ -54,6 +56,8 @@ export class API {
5456

5557
public readonly roleConnections: RoleConnectionsAPI;
5658

59+
public readonly soundboardSounds: SoundboardSoundsAPI;
60+
5761
public readonly stageInstances: StageInstancesAPI;
5862

5963
public readonly stickers: StickersAPI;
@@ -76,6 +80,7 @@ export class API {
7680
this.oauth2 = new OAuth2API(rest);
7781
this.poll = new PollAPI(rest);
7882
this.roleConnections = new RoleConnectionsAPI(rest);
83+
this.soundboardSounds = new SoundboardSoundsAPI(rest);
7984
this.stageInstances = new StageInstancesAPI(rest);
8085
this.stickers = new StickersAPI(rest);
8186
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,
@@ -131,6 +135,10 @@ export interface MappedEvents {
131135
[GatewayDispatchEvents.GuildScheduledEventUserRemove]: [
132136
ToEventProps<GatewayGuildScheduledEventUserRemoveDispatchData>,
133137
];
138+
[GatewayDispatchEvents.GuildSoundboardSoundCreate]: [ToEventProps<GatewayGuildSoundboardSoundCreateDispatch>];
139+
[GatewayDispatchEvents.GuildSoundboardSoundDelete]: [ToEventProps<GatewayGuildSoundboardSoundDeleteDispatch>];
140+
[GatewayDispatchEvents.GuildSoundboardSoundUpdate]: [ToEventProps<GatewayGuildSoundboardSoundUpdateDispatch>];
141+
[GatewayDispatchEvents.GuildSoundboardSoundsUpdate]: [ToEventProps<GatewayGuildSoundboardSoundsUpdateDispatch>];
134142
[GatewayDispatchEvents.GuildStickersUpdate]: [ToEventProps<GatewayGuildStickersUpdateDispatchData>];
135143
[GatewayDispatchEvents.GuildUpdate]: [ToEventProps<GatewayGuildUpdateDispatchData>];
136144
[GatewayDispatchEvents.IntegrationCreate]: [ToEventProps<GatewayIntegrationCreateDispatchData>];

0 commit comments

Comments
 (0)