discordx-ts / discordx

🤖 Create a discord bot with TypeScript and Decorators!
https://discordx.js.org
Apache License 2.0
588 stars 50 forks source link

[Bug]: VoiceStateUpdate returns object but keys returns undefined #959

Closed Johns3n closed 9 months ago

Johns3n commented 9 months ago

What happened?

I have the following listener command in my bot:

import { VoiceState } from "discord.js";
import { Discord, On } from "discordx";

@Discord()
export class Common {
  @On({ event: "voiceStateUpdate" })
  onMessage(
    oldState: VoiceState, 
    newState: VoiceState
  ){
    console.log(oldState);
  }
}

And i have the IntentsBitField.Flags.GuildVoiceStates in my main.ts file and when i run the above command that console outputs the following for me:

[
  VoiceState {
    guild: Guild {
      id: 'REDACTED-FOR-PRIVACY',
      name: 'REDACTED-FOR-PRIVACY',
      icon: null,
      features: [],
      commands: [GuildApplicationCommandManager],
      members: [GuildMemberManager],
      channels: [GuildChannelManager],
      bans: [GuildBanManager],
      roles: [RoleManager],
      presences: PresenceManager {},
      voiceStates: [VoiceStateManager],
      stageInstances: [StageInstanceManager],
      invites: [GuildInviteManager],
      scheduledEvents: [GuildScheduledEventManager],
      autoModerationRules: [AutoModerationRuleManager],
      available: true,
      shardId: 0,
      splash: null,
      banner: null,
      description: null,
      verificationLevel: 0,
      vanityURLCode: null,
      nsfwLevel: 0,
      premiumSubscriptionCount: 0,
      discoverySplash: null,
      memberCount: 2,
      large: false,
      premiumProgressBarEnabled: false,
      applicationId: null,
      afkTimeout: 300,
      afkChannelId: null,
      systemChannelId: 'REDACTED-FOR-PRIVACY',
      premiumTier: 0,
      widgetEnabled: null,
      widgetChannelId: null,
      explicitContentFilter: 0,
      mfaLevel: 0,
      joinedTimestamp: REDACTED-FOR-PRIVACY,
      defaultMessageNotifications: 0,
      systemChannelFlags: [SystemChannelFlagsBitField],
      maximumMembers: 500000,
      maximumPresences: null,
      maxVideoChannelUsers: 25,
      maxStageVideoChannelUsers: 50,
      approximateMemberCount: null,
      approximatePresenceCount: null,
      vanityURLUses: null,
      rulesChannelId: null,
      publicUpdatesChannelId: null,
      preferredLocale: 'en-US',
      safetyAlertsChannelId: null,
      ownerId: 'REDACTED-FOR-PRIVACY',
      emojis: [GuildEmojiManager],
      stickers: [GuildStickerManager]
    },
    id: 'REDACTED-FOR-PRIVACY',
    serverDeaf: null,
    serverMute: null,
    selfDeaf: null,
    selfMute: null,
    selfVideo: null,
    sessionId: null,
    streaming: null,
    channelId: null,
    suppress: null,
    requestToSpeakTimestamp: null
  },
  VoiceState {
    guild: Guild {
      id: 'REDACTED-FOR-PRIVACY',
      name: 'REDACTED-FOR-PRIVACY',
      icon: null,
      features: [],
      commands: [GuildApplicationCommandManager],
      members: [GuildMemberManager],
      channels: [GuildChannelManager],
      bans: [GuildBanManager],
      roles: [RoleManager],
      presences: PresenceManager {},
      voiceStates: [VoiceStateManager],
      stageInstances: [StageInstanceManager],
      invites: [GuildInviteManager],
      scheduledEvents: [GuildScheduledEventManager],
      autoModerationRules: [AutoModerationRuleManager],
      available: true,
      shardId: 0,
      splash: null,
      banner: null,
      description: null,
      verificationLevel: 0,
      vanityURLCode: null,
      nsfwLevel: 0,
      premiumSubscriptionCount: 0,
      discoverySplash: null,
      memberCount: 2,
      large: false,
      premiumProgressBarEnabled: false,
      applicationId: null,
      afkTimeout: 300,
      afkChannelId: null,
      systemChannelId: 'REDACTED-FOR-PRIVACY',
      premiumTier: 0,
      widgetEnabled: null,
      widgetChannelId: null,
      explicitContentFilter: 0,
      mfaLevel: 0,
      joinedTimestamp: REDACTED-FOR-PRIVACY,
      defaultMessageNotifications: 0,
      systemChannelFlags: [SystemChannelFlagsBitField],
      maximumMembers: 500000,
      maximumPresences: null,
      maxVideoChannelUsers: 25,
      maxStageVideoChannelUsers: 50,
      approximateMemberCount: null,
      approximatePresenceCount: null,
      vanityURLUses: null,
      rulesChannelId: null,
      publicUpdatesChannelId: null,
      preferredLocale: 'en-US',
      safetyAlertsChannelId: null,
      ownerId: 'REDACTED-FOR-PRIVACY',
      emojis: [GuildEmojiManager],
      stickers: [GuildStickerManager]
    },
    id: 'REDACTED-FOR-PRIVACY',
    serverDeaf: false,
    serverMute: false,
    selfDeaf: false,
    selfMute: false,
    selfVideo: false,
    sessionId: 'REDACTED-FOR-PRIVACY',
    streaming: false,
    channelId: 'REDACTED-FOR-PRIVACY',
    suppress: false,
    requestToSpeakTimestamp: null
  }
]

but when i try to access ANY member on the oldstate object like oldState.channelId it returns "undefined" in the console log. When my bot joined i made it have all the priviliged gateways enabled and also it joined in the "bot" scope and also had "administrator" as it's bot's permissions.

Am I doing something wrong in trying to access the oldState's and newState's (which does the same) channelId with the above code?

Reproduction

installed discordX as per specs made bot join created class from "what happend" field

Package

discordx

Version

Stable

Relevant log output

No response

Code of Conduct

Johns3n commented 9 months ago

Nevermind, refactored the class into this and it works! :) Hope if someone else has this problem they come across this issue:

import { ArgsOf, Discord, On } from "discordx";

@Discord()
export class Common {
  @On({ event: "voiceStateUpdate" })
  onVoiceStateUpdate([oldState, newState]: ArgsOf<"voiceStateUpdate">){
    console.log(oldState.channelId);
    console.log(newState.channelId);
  }
}