Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Voice Channel Send Effects #9288

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
@@ -0,0 +1,10 @@
'use strict';

const VoiceChannelEffect = require('../../../structures/VoiceChannelEffect');
const Events = require('../../../util/Events');

module.exports = (client, { d: data }) => {
const guild = client.guilds.cache.get(data.guild_id);
if (!guild) return;
client.emit(Events.VoiceChannelEffectSend, new VoiceChannelEffect(data, guild));
Jiralite marked this conversation as resolved.
Show resolved Hide resolved
};
Expand Up @@ -56,6 +56,7 @@ const handlers = Object.fromEntries([
['THREAD_UPDATE', require('./THREAD_UPDATE')],
['TYPING_START', require('./TYPING_START')],
['USER_UPDATE', require('./USER_UPDATE')],
['VOICE_CHANNEL_EFFECT_SEND', require('./VOICE_CHANNEL_EFFECT_SEND')],
['VOICE_SERVER_UPDATE', require('./VOICE_SERVER_UPDATE')],
['VOICE_STATE_UPDATE', require('./VOICE_STATE_UPDATE')],
['WEBHOOKS_UPDATE', require('./WEBHOOKS_UPDATE')],
Expand Down
1 change: 1 addition & 0 deletions packages/discord.js/src/index.js
Expand Up @@ -195,6 +195,7 @@ exports.ThreadMember = require('./structures/ThreadMember');
exports.Typing = require('./structures/Typing');
exports.User = require('./structures/User');
exports.UserContextMenuCommandInteraction = require('./structures/UserContextMenuCommandInteraction');
exports.VoiceChannelEffect = require('./structures/VoiceChannelEffect');
exports.VoiceChannel = require('./structures/VoiceChannel');
exports.VoiceRegion = require('./structures/VoiceRegion');
exports.VoiceState = require('./structures/VoiceState');
Expand Down
58 changes: 58 additions & 0 deletions packages/discord.js/src/structures/VoiceChannelEffect.js
@@ -0,0 +1,58 @@
'use strict';

const { Emoji } = require('./Emoji');

/**
* Represents an effect used in a {@link VoiceChannel}.
*/
class VoiceChannelEffect {

This comment was marked as outdated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably not. Extending Base would mean this would (not publically) add _clone(), _patch(), and _update() to the class which are all irrelevant methods. In addition, valueOf() for this structure would return undefined as there is no id sent in voice channel effects.

constructor(data, guild) {
/**
* The guild where the effect was sent from.
* @type {Guild}
*/
this.guild = guild;

/**
* The id of the channel the effect was sent in.
* @type {Snowflake}
*/
this.channelId = data.channel_id;

/**
* The id of the user that sent the effect.
* @type {Snowflake}
*/
this.userId = data.user_id;

/**
* The emoji of the effect.
* @type {?Emoji}
*/
this.emoji = data.emoji ? new Emoji(guild.client, data.emoji) : null;

// TODO: Revise after discord-api-types.
/**
* The animation type of the effect.
* @type {?number}
*/
this.animationType = data.animation_type ?? null;

/**
* The animation id of the effect.
* @type {?number}
*/
this.animationId = data.animation_id ?? null;
}

/**
* The channel the effect was sent in.
* @type {?VoiceChannel}
* @readonly
*/
get channel() {
return this.guild.channels.resolve(this.channelId);
}
}

module.exports = VoiceChannelEffect;
2 changes: 2 additions & 0 deletions packages/discord.js/src/util/Events.js
Expand Up @@ -67,6 +67,7 @@
* @property {string} ThreadUpdate threadUpdate
* @property {string} TypingStart typingStart
* @property {string} UserUpdate userUpdate
* @property {string} VoiceChannelEffectSend voiceChannelEffectSend
* @property {string} VoiceServerUpdate voiceServerUpdate
* @property {string} VoiceStateUpdate voiceStateUpdate
* @property {string} Warn warn
Expand Down Expand Up @@ -149,6 +150,7 @@ module.exports = {
ThreadUpdate: 'threadUpdate',
TypingStart: 'typingStart',
UserUpdate: 'userUpdate',
VoiceChannelEffectSend: 'voiceChannelEffectSend',
VoiceServerUpdate: 'voiceServerUpdate',
VoiceStateUpdate: 'voiceStateUpdate',
Warn: 'warn',
Expand Down
15 changes: 15 additions & 0 deletions packages/discord.js/typings/index.d.ts
Expand Up @@ -3195,6 +3195,19 @@ export class VoiceChannel extends BaseGuildVoiceChannel {
public type: ChannelType.GuildVoice;
}

export class VoiceChannelEffect {
// TODO: Revise after discord-api-types.
private constructor(data: unknown, guild: Guild);
public guild: Guild;
public channelId: Snowflake;
public userId: Snowflake;
public emoji: Emoji | null;
// TODO: Revise after discord-api-types.
public animationType: 0 | 1 | null;
public animationId: number | null;
public get channel(): VoiceChannel | null;
}

export class VoiceRegion {
private constructor(data: RawVoiceRegionData);
public custom: boolean;
Expand Down Expand Up @@ -4802,6 +4815,7 @@ export interface ClientEvents {
threadUpdate: [oldThread: AnyThreadChannel, newThread: AnyThreadChannel];
typingStart: [typing: Typing];
userUpdate: [oldUser: User | PartialUser, newUser: User];
voiceChannelEffectSend: [voiceChannelEffect: VoiceChannelEffect];
voiceStateUpdate: [oldState: VoiceState, newState: VoiceState];
webhookUpdate: [channel: TextChannel | NewsChannel | VoiceChannel | ForumChannel];
interactionCreate: [interaction: Interaction];
Expand Down Expand Up @@ -5002,6 +5016,7 @@ export enum Events {
ThreadMembersUpdate = 'threadMembersUpdate',
UserUpdate = 'userUpdate',
PresenceUpdate = 'presenceUpdate',
VoiceChannelEffectSend = 'voiceChannelEffectSend',
VoiceServerUpdate = 'voiceServerUpdate',
VoiceStateUpdate = 'voiceStateUpdate',
TypingStart = 'typingStart',
Expand Down