discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

newChannel.channelId doesn't update if bot is kicked from a Voice Channel #6918

Closed costaluu closed 2 years ago

costaluu commented 2 years ago

Issue description

When a bot is forced to leave a voice channel, the newChannel is not updated properly. So the properties of newChannel are almost the same as oldChannel making it non-trivial (or even infeasible) to detect when the bot was forcibly disconnected

disconnect

That's what i code

code

I got this.

log

Basically the first two lines are fired when the bot join in the voice channel and the last two lines fired when the bot is forcefully disconnected.

The expected behavior was that newChannel.channelId would be null.

Idk, if that's is expected or its a bug, if this is expected, can you guys suggest me how can i detect this?

Info

I'm using erela.js (lavalink client) for connect my bot to a Voice Channel

Code sample

client.on('voiceStateUpdate', (oldChannel, newChannel) => {
    console.log(oldChannel.channelId)
    console.log(newChannel.channelId)
})

discord.js version

13.3.0

Node.js version

16.9.1

Operating system

Windows

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

USER, CHANNEL, GUILD_MEMBER, MESSAGE, REACTION

Which gateway intents are you subscribing to?

GUILDS, GUILD_MEMBERS, GUILD_VOICE_STATES, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS, DIRECT_MESSAGE_TYPING

I have tested this issue on a development release

No response

SpaceEEC commented 2 years ago

I'm unable to reproduce this.

costaluu commented 2 years ago

I'm unable to reproduce this.

@SpaceEEC did you kicked your bot? What was the result?

SpaceEEC commented 2 years ago

When joining a voice channel, I see null and the id of the voice channel in the console. When disconnecting the bot through the context menu I see the id of the voice channel and null in the console.

costaluu commented 2 years ago

Can you provide me your Node and Discord.js version?

SpaceEEC commented 2 years ago

djs 13.3.0 node 16.13.0

costaluu commented 2 years ago

image

Yeah, i update my node to16.13.0 and it's fine now \o/, since it's a node problem i'm going to close this issue

@SpaceEEC Thank you!

costaluu commented 2 years ago

Ok, i don't know why but this issue showed up again and i didn't change my node version... Do you guys have any idea what's going on here?

ImRodry commented 2 years ago

Try running node -v or process.version to see if you're actually running on the version of node you think you're running since that seemed to be the issue last time

costaluu commented 2 years ago

@ImRodry There is a new log here

image

Last time i just updated my node and it worked like a charm

ImRodry commented 2 years ago

From that log it seems like you’re updating something else on the voice state, try logging the full objects instead

costaluu commented 2 years ago

@ImRodry Sorry for the late response there is the complete log, logging the old and new voice state... Bot join in VC

Process node: v16.13.0
Bot connected!
Node "localhost" connected.
VoiceState {
  guild: <ref *1> Guild {
    id: '858470922004070421',
    name: 'Trevas',
    icon: null,
    features: [],
    commands: GuildApplicationCommandManager {
      permissions: [ApplicationCommandPermissionsManager],
      guild: [Circular *1]
    },
    members: GuildMemberManager { guild: [Circular *1] },
    channels: GuildChannelManager { guild: [Circular *1] },
    bans: GuildBanManager { guild: [Circular *1] },
    roles: RoleManager { guild: [Circular *1] },
    presences: PresenceManager {},
    voiceStates: VoiceStateManager { guild: [Circular *1] },
    stageInstances: StageInstanceManager { guild: [Circular *1] },
    invites: GuildInviteManager { guild: [Circular *1] },
    deleted: false,
    available: true,
    shardId: 0,
    splash: null,
    banner: null,
    description: null,
    verificationLevel: 'NONE',
    vanityURLCode: null,
    nsfwLevel: 'DEFAULT',
    discoverySplash: null,
    memberCount: 7,
    large: false,
    applicationId: null,
    afkTimeout: 300,
    afkChannelId: null,
    systemChannelId: '858470922004070424',
    premiumTier: 'NONE',
    premiumSubscriptionCount: 0,
    explicitContentFilter: 'DISABLED',
    mfaLevel: 'NONE',
    joinedTimestamp: 1635884932072,
    defaultMessageNotifications: 'ALL_MESSAGES',
    systemChannelFlags: SystemChannelFlags { bitfield: 0 },
    maximumMembers: 250000,
    maximumPresences: null,
    approximateMemberCount: null,
    approximatePresenceCount: null,
    vanityURLUses: null,
    rulesChannelId: null,
    publicUpdatesChannelId: null,
    preferredLocale: 'en-US',
    ownerId: '358060034489581571',
    emojis: GuildEmojiManager { guild: [Circular *1] },
    stickers: GuildStickerManager { guild: [Circular *1] }
  },
  id: '905191374121484289',
  serverDeaf: null,
  serverMute: null,
  selfDeaf: null,
  selfMute: null,
  selfVideo: null,
  sessionId: null,
  streaming: null,
  channelId: null,
  requestToSpeakTimestamp: null
}
VoiceState {
  guild: <ref *1> Guild {
    id: '858470922004070421',
    name: 'Trevas',
    icon: null,
    features: [],
    commands: GuildApplicationCommandManager {
      permissions: [ApplicationCommandPermissionsManager],
      guild: [Circular *1]
    },
    members: GuildMemberManager { guild: [Circular *1] },
    channels: GuildChannelManager { guild: [Circular *1] },
    bans: GuildBanManager { guild: [Circular *1] },
    roles: RoleManager { guild: [Circular *1] },
    presences: PresenceManager {},
    voiceStates: VoiceStateManager { guild: [Circular *1] },
    stageInstances: StageInstanceManager { guild: [Circular *1] },
    invites: GuildInviteManager { guild: [Circular *1] },
    deleted: false,
    available: true,
    shardId: 0,
    splash: null,
    banner: null,
    description: null,
    verificationLevel: 'NONE',
    vanityURLCode: null,
    nsfwLevel: 'DEFAULT',
    discoverySplash: null,
    memberCount: 7,
    large: false,
    applicationId: null,
    afkTimeout: 300,
    afkChannelId: null,
    systemChannelId: '858470922004070424',
    premiumTier: 'NONE',
    premiumSubscriptionCount: 0,
    explicitContentFilter: 'DISABLED',
    mfaLevel: 'NONE',
    joinedTimestamp: 1635884932072,
    defaultMessageNotifications: 'ALL_MESSAGES',
    systemChannelFlags: SystemChannelFlags { bitfield: 0 },
    maximumMembers: 250000,
    maximumPresences: null,
    approximateMemberCount: null,
    approximatePresenceCount: null,
    vanityURLUses: null,
    rulesChannelId: null,
    publicUpdatesChannelId: null,
    preferredLocale: 'en-US',
    ownerId: '358060034489581571',
    emojis: GuildEmojiManager { guild: [Circular *1] },
    stickers: GuildStickerManager { guild: [Circular *1] }
  },
  id: '905191374121484289',
  serverDeaf: false,
  serverMute: false,
  selfDeaf: false,
  selfMute: false,
  selfVideo: false,
  sessionId: '59529490977804728ed374132f8d04c0',
  streaming: null,
  channelId: '858470922004070425',
  suppress: false,
  requestToSpeakTimestamp: 0
}

Bot is kicked

VoiceState {
  guild: <ref *1> Guild {
    id: '858470922004070421',
    name: 'Trevas',
    icon: null,
    features: [],
    commands: GuildApplicationCommandManager {
      permissions: [ApplicationCommandPermissionsManager],
      guild: [Circular *1]
    },
    members: GuildMemberManager { guild: [Circular *1] },
    channels: GuildChannelManager { guild: [Circular *1] },
    bans: GuildBanManager { guild: [Circular *1] },
    roles: RoleManager { guild: [Circular *1] },
    presences: PresenceManager {},
    voiceStates: VoiceStateManager { guild: [Circular *1] },
    stageInstances: StageInstanceManager { guild: [Circular *1] },
    invites: GuildInviteManager { guild: [Circular *1] },
    deleted: false,
    available: true,
    shardId: 0,
    splash: null,
    banner: null,
    description: null,
    verificationLevel: 'NONE',
    vanityURLCode: null,
    nsfwLevel: 'DEFAULT',
    discoverySplash: null,
    memberCount: 7,
    large: false,
    applicationId: null,
    afkTimeout: 300,
    afkChannelId: null,
    systemChannelId: '858470922004070424',
    premiumTier: 'NONE',
    premiumSubscriptionCount: 0,
    explicitContentFilter: 'DISABLED',
    mfaLevel: 'NONE',
    joinedTimestamp: 1635884932072,
    defaultMessageNotifications: 'ALL_MESSAGES',
    systemChannelFlags: SystemChannelFlags { bitfield: 0 },
    maximumMembers: 250000,
    maximumPresences: null,
    approximateMemberCount: null,
    approximatePresenceCount: null,
    vanityURLUses: null,
    rulesChannelId: null,
    publicUpdatesChannelId: null,
    preferredLocale: 'en-US',
    ownerId: '358060034489581571',
    emojis: GuildEmojiManager { guild: [Circular *1] },
    stickers: GuildStickerManager { guild: [Circular *1] }
  },
  id: '905191374121484289',
  serverDeaf: false,
  serverMute: false,
  selfDeaf: false,
  selfMute: false,
  selfVideo: false,
  sessionId: '59529490977804728ed374132f8d04c0',
  streaming: null,
  channelId: '858470922004070425',
  suppress: false,
  requestToSpeakTimestamp: 0
}
VoiceState {
  guild: <ref *1> Guild {
    id: '858470922004070421',
    name: 'Trevas',
    icon: null,
    features: [],
    commands: GuildApplicationCommandManager {
      permissions: [ApplicationCommandPermissionsManager],
      guild: [Circular *1]
    },
    members: GuildMemberManager { guild: [Circular *1] },
    channels: GuildChannelManager { guild: [Circular *1] },
    bans: GuildBanManager { guild: [Circular *1] },
    roles: RoleManager { guild: [Circular *1] },
    presences: PresenceManager {},
    voiceStates: VoiceStateManager { guild: [Circular *1] },
    stageInstances: StageInstanceManager { guild: [Circular *1] },
    invites: GuildInviteManager { guild: [Circular *1] },
    deleted: false,
    available: true,
    shardId: 0,
    splash: null,
    banner: null,
    description: null,
    verificationLevel: 'NONE',
    vanityURLCode: null,
    nsfwLevel: 'DEFAULT',
    discoverySplash: null,
    memberCount: 7,
    large: false,
    applicationId: null,
    afkTimeout: 300,
    afkChannelId: null,
    systemChannelId: '858470922004070424',
    premiumTier: 'NONE',
    premiumSubscriptionCount: 0,
    explicitContentFilter: 'DISABLED',
    mfaLevel: 'NONE',
    joinedTimestamp: 1635884932072,
    defaultMessageNotifications: 'ALL_MESSAGES',
    systemChannelFlags: SystemChannelFlags { bitfield: 0 },
    maximumMembers: 250000,
    maximumPresences: null,
    approximateMemberCount: null,
    approximatePresenceCount: null,
    vanityURLUses: null,
    rulesChannelId: null,
    publicUpdatesChannelId: null,
    preferredLocale: 'en-US',
    ownerId: '358060034489581571',
    emojis: GuildEmojiManager { guild: [Circular *1] },
    stickers: GuildStickerManager { guild: [Circular *1] }
  },
  id: '905191374121484289',
  serverDeaf: false,
  serverMute: false,
  selfDeaf: false,
  selfMute: false,
  selfVideo: false,
  sessionId: '59529490977804728ed374132f8d04c0',
  streaming: null,
  channelId: '858470922004070425',
  suppress: false,
  requestToSpeakTimestamp: 0
}
Jiralite commented 2 years ago

I'm also not able to reproduce this. Looking over your issue again, I see this:

I'm using erela.js (lavalink client) for connect my bot to a Voice Channel

I have no idea what this is, but it looks third-party to me. If it is, perhaps you should be investigating this third-party area too. That also means attempting to reproduce with discord.js alone.

SpaceEEC commented 2 years ago

@Jiralite was right, it's erela.js' fault, see this line in Manager#updateVoiceState.

This was introduced with https://github.com/MenuDocs/erela.js/commit/1e7fc10a61b2e50a654363ed3296201121fa6ac8 for reasons unknown to me (I don't know erela.js' internals).

Possible workarounds:

You probably want to raise an issue on their repo either way so no workaround is required.