Skip to content

Commit 1972eb2

Browse files
committed
feat: Voice Channel Send Effects (#9288)
1 parent c8ef899 commit 1972eb2

File tree

6 files changed

+93
-0
lines changed

6 files changed

+93
-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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
// TODO: Revise after discord-api-types.
35+
/**
36+
* The animation type of the effect.
37+
* @type {?number}
38+
*/
39+
this.animationType = data.animation_type ?? null;
40+
41+
/**
42+
* The animation id of the effect.
43+
* @type {?number}
44+
*/
45+
this.animationId = data.animation_id ?? null;
46+
}
47+
48+
/**
49+
* The channel the effect was sent in.
50+
* @type {?VoiceChannel}
51+
* @readonly
52+
*/
53+
get channel() {
54+
return this.guild.channels.resolve(this.channelId);
55+
}
56+
}
57+
58+
module.exports = VoiceChannelEffect;

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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,6 +3555,19 @@ export class VoiceChannel extends BaseGuildVoiceChannel {
35553555
public type: ChannelType.GuildVoice;
35563556
}
35573557

3558+
export class VoiceChannelEffect {
3559+
// TODO: Revise after discord-api-types.
3560+
private constructor(data: unknown, guild: Guild);
3561+
public guild: Guild;
3562+
public channelId: Snowflake;
3563+
public userId: Snowflake;
3564+
public emoji: Emoji | null;
3565+
// TODO: Revise after discord-api-types.
3566+
public animationType: 0 | 1 | null;
3567+
public animationId: number | null;
3568+
public get channel(): VoiceChannel | null;
3569+
}
3570+
35583571
export class VoiceRegion {
35593572
private constructor(data: RawVoiceRegionData);
35603573
public custom: boolean;
@@ -5159,6 +5172,7 @@ export interface ClientEvents {
51595172
threadUpdate: [oldThread: AnyThreadChannel, newThread: AnyThreadChannel];
51605173
typingStart: [typing: Typing];
51615174
userUpdate: [oldUser: User | PartialUser, newUser: User];
5175+
voiceChannelEffectSend: [voiceChannelEffect: VoiceChannelEffect];
51625176
voiceStateUpdate: [oldState: VoiceState, newState: VoiceState];
51635177
webhooksUpdate: [channel: TextChannel | AnnouncementChannel | VoiceChannel | ForumChannel | MediaChannel];
51645178
interactionCreate: [interaction: Interaction];
@@ -5353,6 +5367,7 @@ export enum Events {
53535367
ThreadMembersUpdate = 'threadMembersUpdate',
53545368
UserUpdate = 'userUpdate',
53555369
PresenceUpdate = 'presenceUpdate',
5370+
VoiceChannelEffectSend = 'voiceChannelEffectSend',
53565371
VoiceServerUpdate = 'voiceServerUpdate',
53575372
VoiceStateUpdate = 'voiceStateUpdate',
53585373
TypingStart = 'typingStart',

0 commit comments

Comments
 (0)