Skip to content

Commit

Permalink
Update Guild Sounboard Sounds Update receive event
Browse files Browse the repository at this point in the history
  • Loading branch information
LonelyDeathVGX committed Oct 24, 2024
1 parent 1278afa commit fa19b6b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
13 changes: 4 additions & 9 deletions lib/gateway/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,10 @@ export async function GUILD_SOUNDBOARD_SOUND_UPDATE(data: DispatchEventMap["GUIL
}

export async function GUILD_SOUNDBOARD_SOUNDS_UPDATE(data: DispatchEventMap["GUILD_SOUNDBOARD_SOUNDS_UPDATE"], shard: Shard): Promise<void> {
const guild = shard.client.guilds.get(data[0].guild_id);
if (guild) {
const oldSounds = data.map(rawSound => {
const sound = guild.soundboardSounds.get(rawSound.sound_id);
return sound?.toJSON() ?? null;
});
shard.client.emit("guildSoundboardSoundsUpdate", data.map(sound => guild.soundboardSounds.update(sound)), oldSounds);
}
shard.client.emit("guildSoundboardSoundsUpdate", data.map(sound => new Soundboard(sound, shard.client)), [null]);
const guild = shard.client.guilds.get(data.guild_id);
const oldSoundboardSounds = data.soundboard_sounds.map(rawSound => guild?.soundboardSounds.get(rawSound.sound_id)?.toJSON() ?? null);
const newSoundboardSounds = data.soundboard_sounds.map(sound => guild?.soundboardSounds.update(sound) ?? new Soundboard(sound, shard.client));
shard.client.emit("guildSoundboardSoundsUpdate", newSoundboardSounds, oldSoundboardSounds, data.guild_id);
}

export async function GUILD_STICKERS_UPDATE(data: DispatchEventMap["GUILD_STICKERS_UPDATE"], shard: Shard): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion lib/types/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export interface ClientEvents {
/** @event Emitted when a guild's soundboard sound is updated. Requires the `GUILD_EXPRESSIONS` intent. */
guildSoundboardSoundUpdate: [soundboardSound: Soundboard, oldSoundboardSound: JSONSoundboard | null];
/** @event Emitted when multiple guild's soundboard sounds are updated. Requires the `GUILD_EXPRESSIONS` intent. */
guildSoundboardSoundsUpdate: [soundboardSounds: Array<Soundboard>, oldSoundboardSounds: Array<JSONSoundboard | null>];
guildSoundboardSoundsUpdate: [soundboardSounds: Array<Soundboard>, oldSoundboardSounds: Array<JSONSoundboard | null>, guildID: string];
/** @event Emitted when a guild's stickers are updated. Requires the `GUILD_EXPRESSIONS` intent. */
guildStickersUpdate: [guild: Guild | Uncached, stickers: Array<Sticker>, oldStickers: Array<Sticker> | null];
/** @event Emitted when a guild becomes unavailable. Requires the `GUILDS` intent. */
Expand Down
5 changes: 4 additions & 1 deletion lib/types/gateway-raw.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,10 @@ export interface GuildSoundboardSoundUpdatePacket extends BaseDispatchPacket {
}

export interface GuildSoundboardSoundsUpdatePacket extends BaseDispatchPacket {
d: Array<RawSoundboard & { guild_id: string; }>;
d: {
guild_id: string;
soundboard_sounds: Array<RawSoundboard & { guild_id: string; }>;
};
t: "GUILD_SOUNDBOARD_SOUNDS_UPDATE";
}

Expand Down

0 comments on commit fa19b6b

Please sign in to comment.