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

Bug: VoiceStateUpdate newState channel holds the GuildMember object #6665

Closed
topjor opened this issue Sep 19, 2021 · 6 comments
Closed

Bug: VoiceStateUpdate newState channel holds the GuildMember object #6665

topjor opened this issue Sep 19, 2021 · 6 comments
Labels

Comments

@topjor
Copy link

topjor commented Sep 19, 2021

Issue description

When voiceStateUpdate's are received, the channel property is not always correctly set. I believe this is only the case for the newState, I have not observed any wrong data in the oldState.
I have only looked at the channel and member properties thus far, though I would advise to inspect all to ensure correctness.

In the newState the channel property has the same value as the member property, (a GuildMember object, instead of a Channel or null)
This is the case when anyone joins, leaves or moves channel, it does not matter who, same for the bot itself)

Further information:

I am using typescript, and a logger that also dumps what type of object is logged, giving proper insight to variable values.
I am also using erela.js for my bots voice system, though that should not matter as the issue is also observed for any other user then the bot.

Codesample

client.on("voiceStateUpdate", (oldState, newState) => {
	bot.logger.debug({oldState: {
		member: oldState.member,
		member_id: oldState.member?.id,
		channel: oldState.channel,
		hannel_id: oldState.channel?.id,
	  }, newState: {
		member: newState.member,
		member_id: newState.member?.id,
		channel: newState.member,
		channel_id: newState.member?.id,
	}});
}

Debug output

oldState: {
    member: GuildMember {
      guild: [Guild],
      joinedTimestamp: 1618574657201,
      premiumSinceTimestamp: null,
      deleted: false,
      nickname: null,
      pending: false,
      _roles: [Array],
      user: [User]
    },
    member_id: '705830325598683217',
    channel: null,
    channel_id: undefined
  },
  newState: {
    member: GuildMember {
      guild: [Guild],
      joinedTimestamp: 1618574657201,
      premiumSinceTimestamp: null,
      deleted: false,
      nickname: null,
      pending: false,
      _roles: [Array],
      user: [User]
    },
    member_id: '705830325598683217',
    channel: GuildMember {
      guild: [Guild],
      joinedTimestamp: 1618574657201,
      premiumSinceTimestamp: null,
      deleted: false,
      nickname: null,
      pending: false,
      _roles: [Array],
      user: [User]
    },
    channel_id: '705830325598683217'
  }
}

discord.js version

13.1.0

Node.js version

16.8.0

Operating system

Linux

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

GUILDS, GUILD_VOICE_STATES

I have tested this issue on a development release

No response

@topjor
Copy link
Author

topjor commented Sep 19, 2021

my project source:
https://gitlab.com/j0dev/discord/musicbot
the voiceStateUpdate event listener
https://gist.github.com/topjor/df6d070b5b0b22f0981cc8f8a824e9ff

should you wish to run it yourself, add the file from the gist in the src/bot/events directory, and add a new voiceStateUpdate instance to the eventList array in the index.ts file in the same directory and the bot will load the event accordingly

@topjor topjor changed the title Bug: VoiceStateUpdate newState channel holds the GuildMember object when someone disconnects or changes channel Bug: VoiceStateUpdate newState channel holds the GuildMember object Sep 19, 2021
@ImRodry
Copy link
Contributor

ImRodry commented Sep 19, 2021

You're logging the value of newState.member on the channel field, that's why you're getting this error
image
Fixing this to say channel instead of member gets rid of the error.

@topjor
Copy link
Author

topjor commented Sep 19, 2021

Thank you, god I am getting sloppy, forgive me, its weekend.
I do however have the issue if the bot itself disconnects, that in the newState holds the old channel when force disconnected

{
  oldState: {
    member: GuildMember {
      guild: [Guild],
      joinedTimestamp: 1629891872123,
      premiumSinceTimestamp: null,
      deleted: false,
      nickname: null,
      pending: false,
      _roles: [Array],
      user: [ClientUser]
    },
    member_id: '880052962846707722',
    channel: VoiceChannel {
      type: 'GUILD_VOICE',
      deleted: false,
      guild: [Guild],
      guildId: '832230526919114853',
      parentId: '832230526919114855',
      permissionOverwrites: [PermissionOverwriteManager],
      id: '832230526919114857',
      name: 'General',
      rawPosition: 0,
      rtcRegion: null,
      bitrate: 64000,
      userLimit: 0
    },
    channel_id: '832230526919114857'
  },
  newState: {
    member: GuildMember {
      guild: [Guild],
      joinedTimestamp: 1629891872123,
      premiumSinceTimestamp: null,
      deleted: false,
      nickname: null,
      pending: false,
      _roles: [Array],
      user: [ClientUser]
    },
    member_id: '880052962846707722',
    channel: VoiceChannel {
      type: 'GUILD_VOICE',
      deleted: false,
      guild: [Guild],
      guildId: '832230526919114853',
      parentId: '832230526919114855',
      permissionOverwrites: [PermissionOverwriteManager],
      id: '832230526919114857',
      name: 'General',
      rawPosition: 0,
      rtcRegion: null,
      bitrate: 64000,
      userLimit: 0
    },
    channel_id: '832230526919114857'
  }
}

edit: it appears my clipboard did not want to copy properly the first time

@ImRodry
Copy link
Contributor

ImRodry commented Sep 19, 2021

I cannot reproduce that behavior with the exact same intents and event you provided, not sure what's wrong there but it must be something else that you added

@topjor
Copy link
Author

topjor commented Sep 19, 2021

I have run some tests, I have come to the conclusion that the voice library I am using is messing up the event, I have raised an issue with erela.js: MenuDocs/erela.js#136

@kyranet
Copy link
Member

kyranet commented Sep 28, 2021

Since this is an external library's fault (and cannot reproduce with just discord.js), I'll close this issue and label as invalid.

@kyranet kyranet closed this as completed Sep 28, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants