fix: VoiceState#member nullable (#995)

* fix(types/voice): member field in VoiceState is nullable

* member is optional for live stages

* Update JSDoc comment block for VoiceState#member

* Revert "member is optional for live stages"

This reverts commit 2faa8b129b.

* feat(handlers/voice): add voiceLurkerJoin event
This commit is contained in:
rigormorrtiss
2021-06-04 22:45:47 +04:00
committed by GitHub
parent 7b9da2cb1f
commit 7750f8f467
3 changed files with 8 additions and 4 deletions

View File

@@ -9,6 +9,9 @@ export async function handleVoiceStateUpdate(data: DiscordGatewayPayload) {
const payload = data.d as VoiceState;
if (!payload.guildId) return;
// The "member" field in the payload is `null` if the user is in a live stage but not in the guild.
if (payload.member === null) return eventHandlers.voiceLurkerJoin?.(payload);
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
if (!guild) return;

View File

@@ -9,8 +9,7 @@ import type { StageInstance } from "../channels/stage_instance.ts";
import type { ThreadMember } from "../channels/threads/thread_member.ts";
import type { ThreadMembersUpdate } from "../channels/threads/thread_members_update.ts";
import type { Emoji } from "../emojis/emoji.ts";
import type { GatewayPayload } from "../gateway/gateway_payload.ts";
import type { DiscordGatewayPayload } from "../gateway/gateway_payload.ts";
import type { DiscordGatewayPayload, GatewayPayload } from "../gateway/gateway_payload.ts";
import type { IntegrationCreateUpdate } from "../integrations/integration_create_update.ts";
import type { IntegrationDelete } from "../integrations/integration_delete.ts";
import type { ApplicationCommandCreateUpdateDelete } from "../interactions/commands/application_command_create_update_delete.ts";
@@ -145,6 +144,8 @@ export type EventHandlersDefinitions = {
voiceChannelLeave: [member: DiscordenoMember, channelId: bigint];
/** Sent when a user switches the voice channel */
voiceChannelSwitch: [member: DiscordenoMember, channelId: bigint, oldChannelId: bigint];
/** Sent when a user/lurker joins a live stage, but they are not inside the guild. */
voiceLurkerJoin: [voiceState: VoiceState];
/** Sent when a voice server is updated with information for making the bot connect to a voice channel. */
voiceServerUpdate: [payload: VoiceServerUpdate, guild: DiscordenoGuild];
/** Sent when someone joins/leaves/moves voice channels. */

View File

@@ -8,8 +8,8 @@ export interface VoiceState {
channelId: string | null;
/** The user id this voice state is for */
userId: string;
/** The guild member this voice state is for */
member?: GuildMemberWithUser;
/** The guild member this voice state is for, or `null` if the user is in a live stage but not in the guild */
member?: GuildMemberWithUser | null;
/** The session id for this voice state */
sessionId: string;
/** Whether this user is deafened by the server */