Skip to content

Commit 6775175

Browse files
feat: Voice Channel Effect Send (#10318)
* feat: Voice Channel Send Effects (#9288) * feat: add soundboard fields * chore: address TODO * docs: volume is a closed interval * types: use `GatewayVoiceChannelEffectSendDispatchData` * refactor: prefer getting from cache * fix: correctly access cache Co-authored-by: Danial Raza <[email protected]> --------- Co-authored-by: Danial Raza <[email protected]>
1 parent e2df0e0 commit 6775175

File tree

7 files changed

+111
-0
lines changed

7 files changed

+111
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const VoiceChannelEffect = require('../../../structures/VoiceChannelEffect');
4+
const Events = require('../../../util/Events');
5+
6+
module.exports = (client, { d: data }) => {
7+
const guild = client.guilds.cache.get(data.guild_id);
8+
if (!guild) return;
9+
10+
/**
11+
* Emmited when someone sends an effect, such as an emoji reaction, in a voice channel the client is connected to.
12+
* @event Client#voiceChannelEffectSend
13+
* @param {VoiceChannelEffect} voiceChannelEffect The sent voice channel effect
14+
*/
15+
client.emit(Events.VoiceChannelEffectSend, new VoiceChannelEffect(data, guild));
16+
};

packages/discord.js/src/client/websocket/handlers/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const handlers = Object.fromEntries([
6060
['THREAD_UPDATE', require('./THREAD_UPDATE')],
6161
['TYPING_START', require('./TYPING_START')],
6262
['USER_UPDATE', require('./USER_UPDATE')],
63+
['VOICE_CHANNEL_EFFECT_SEND', require('./VOICE_CHANNEL_EFFECT_SEND')],
6364
['VOICE_SERVER_UPDATE', require('./VOICE_SERVER_UPDATE')],
6465
['VOICE_STATE_UPDATE', require('./VOICE_STATE_UPDATE')],
6566
['WEBHOOKS_UPDATE', require('./WEBHOOKS_UPDATE')],

packages/discord.js/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ exports.ThreadOnlyChannel = require('./structures/ThreadOnlyChannel');
206206
exports.Typing = require('./structures/Typing');
207207
exports.User = require('./structures/User');
208208
exports.UserContextMenuCommandInteraction = require('./structures/UserContextMenuCommandInteraction');
209+
exports.VoiceChannelEffect = require('./structures/VoiceChannelEffect');
209210
exports.VoiceChannel = require('./structures/VoiceChannel');
210211
exports.VoiceRegion = require('./structures/VoiceRegion');
211212
exports.VoiceState = require('./structures/VoiceState');
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
3+
const { Emoji } = require('./Emoji');
4+
5+
/**
6+
* Represents an effect used in a {@link VoiceChannel}.
7+
*/
8+
class VoiceChannelEffect {
9+
constructor(data, guild) {
10+
/**
11+
* The guild where the effect was sent from.
12+
* @type {Guild}
13+
*/
14+
this.guild = guild;
15+
16+
/**
17+
* The id of the channel the effect was sent in.
18+
* @type {Snowflake}
19+
*/
20+
this.channelId = data.channel_id;
21+
22+
/**
23+
* The id of the user that sent the effect.
24+
* @type {Snowflake}
25+
*/
26+
this.userId = data.user_id;
27+
28+
/**
29+
* The emoji of the effect.
30+
* @type {?Emoji}
31+
*/
32+
this.emoji = data.emoji ? new Emoji(guild.client, data.emoji) : null;
33+
34+
/**
35+
* The animation type of the effect.
36+
* @type {?VoiceChannelEffectSendAnimationType}
37+
*/
38+
this.animationType = data.animation_type ?? null;
39+
40+
/**
41+
* The animation id of the effect.
42+
* @type {?number}
43+
*/
44+
this.animationId = data.animation_id ?? null;
45+
46+
/**
47+
* The id of the soundboard sound for soundboard effects.
48+
* @type {?(Snowflake|number)}
49+
*/
50+
this.soundId = data.sound_id ?? null;
51+
52+
/**
53+
* The volume of the soundboard sound [0-1] for soundboard effects.
54+
* @type {?number}
55+
*/
56+
this.soundVolume = data.sound_volume ?? null;
57+
}
58+
59+
/**
60+
* The channel the effect was sent in.
61+
* @type {?VoiceChannel}
62+
* @readonly
63+
*/
64+
get channel() {
65+
return this.guild.channels.cache.get(this.channelId) ?? null;
66+
}
67+
}
68+
69+
module.exports = VoiceChannelEffect;

packages/discord.js/src/util/APITypes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,11 @@
589589
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/VideoQualityMode}
590590
*/
591591

592+
/**
593+
* @external VoiceChannelEffectSendAnimationType
594+
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/VoiceChannelEffectSendAnimationType}
595+
*/
596+
592597
/**
593598
* @external WebhookType
594599
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/WebhookType}

packages/discord.js/src/util/Events.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
* @property {string} ThreadUpdate threadUpdate
7373
* @property {string} TypingStart typingStart
7474
* @property {string} UserUpdate userUpdate
75+
* @property {string} VoiceChannelEffectSend voiceChannelEffectSend
7576
* @property {string} VoiceServerUpdate voiceServerUpdate
7677
* @property {string} VoiceStateUpdate voiceStateUpdate
7778
* @property {string} Warn warn
@@ -154,6 +155,7 @@ module.exports = {
154155
ThreadUpdate: 'threadUpdate',
155156
TypingStart: 'typingStart',
156157
UserUpdate: 'userUpdate',
158+
VoiceChannelEffectSend: 'voiceChannelEffectSend',
157159
VoiceServerUpdate: 'voiceServerUpdate',
158160
VoiceStateUpdate: 'voiceStateUpdate',
159161
Warn: 'warn',

packages/discord.js/typings/index.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ import {
166166
GuildScheduledEventRecurrenceRuleFrequency,
167167
GatewaySendPayload,
168168
GatewayDispatchPayload,
169+
VoiceChannelEffectSendAnimationType,
170+
GatewayVoiceChannelEffectSendDispatchData,
169171
} from 'discord-api-types/v10';
170172
import { ChildProcess } from 'node:child_process';
171173
import { EventEmitter } from 'node:events';
@@ -3557,6 +3559,19 @@ export class VoiceChannel extends BaseGuildVoiceChannel {
35573559
public type: ChannelType.GuildVoice;
35583560
}
35593561

3562+
export class VoiceChannelEffect {
3563+
private constructor(data: GatewayVoiceChannelEffectSendDispatchData, guild: Guild);
3564+
public guild: Guild;
3565+
public channelId: Snowflake;
3566+
public userId: Snowflake;
3567+
public emoji: Emoji | null;
3568+
public animationType: VoiceChannelEffectSendAnimationType | null;
3569+
public animationId: number | null;
3570+
public soundId: Snowflake | number | null;
3571+
public soundVolume: number | null;
3572+
public get channel(): VoiceChannel | null;
3573+
}
3574+
35603575
export class VoiceRegion {
35613576
private constructor(data: RawVoiceRegionData);
35623577
public custom: boolean;
@@ -5163,6 +5178,7 @@ export interface ClientEvents {
51635178
threadUpdate: [oldThread: AnyThreadChannel, newThread: AnyThreadChannel];
51645179
typingStart: [typing: Typing];
51655180
userUpdate: [oldUser: User | PartialUser, newUser: User];
5181+
voiceChannelEffectSend: [voiceChannelEffect: VoiceChannelEffect];
51665182
voiceStateUpdate: [oldState: VoiceState, newState: VoiceState];
51675183
webhooksUpdate: [channel: TextChannel | AnnouncementChannel | VoiceChannel | ForumChannel | MediaChannel];
51685184
interactionCreate: [interaction: Interaction];
@@ -5357,6 +5373,7 @@ export enum Events {
53575373
ThreadMembersUpdate = 'threadMembersUpdate',
53585374
UserUpdate = 'userUpdate',
53595375
PresenceUpdate = 'presenceUpdate',
5376+
VoiceChannelEffectSend = 'voiceChannelEffectSend',
53605377
VoiceServerUpdate = 'voiceServerUpdate',
53615378
VoiceStateUpdate = 'voiceStateUpdate',
53625379
TypingStart = 'typingStart',

0 commit comments

Comments
 (0)