discordjs / discord.js

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

VoiceChannel.joinable erroring for "cannot read .has of null" #2252

Closed FireController1847 closed 6 years ago

FireController1847 commented 6 years ago

Please describe the problem you are having in as much detail as possible: Getting a voice connection's channel and running .joinable is (seemingly randomly) erroring with the error below. It may not be random or related to the client not being in cache on a new server, but I haven't tested that and the only time I can reproduce it is in production.

7|Pandora  | [Shard 5] TypeError: Cannot read property 'has' of null
7|Pandora  |     at VoiceChannel.get joinable [as joinable] (/home/fire/bots/pandora/node_modules/discord.js/src/structures/VoiceChannel.js:64:47)
7|Pandora  |     at YouTube.handleListener (/home/fire/bots/pandora/src/Music/youtube.js:57:23)
7|Pandora  |     at StreamDispatcher.dispatcher.on.r (/home/fire/bots/pandora/src/Music/youtube.js:196:19)
7|Pandora  |     at emitOne (events.js:116:13)
7|Pandora  |     at StreamDispatcher.emit (events.js:211:7)
7|Pandora  |     at StreamDispatcher.destroy (/home/fire/bots/pandora/node_modules/discord.js/src/client/voice/dispatcher/StreamDispatcher.js:294:10)
7|Pandora  |     at AudioPlayer.destroyCurrentStream (/home/fire/bots/pandora/node_modules/discord.js/src/client/voice/player/AudioPlayer.js:77:18)
7|Pandora  |     at VoiceConnection.AudioPlayer.voiceConnection.once (/home/fire/bots/pandora/node_modules/discord.js/src/client/voice/player/AudioPlayer.js:42:53)
7|Pandora  |     at Object.onceWrapper (events.js:313:30)
7|Pandora  |     at emitNone (events.js:111:20)

Include a reproducible code sample here, if possible:

// Designed for eval.
(async () => {
  // Join a voice channel
  const vc = m.member.voiceChannel;
  const conn = await vc.join();
  console.log(conn.channel.joinable);
})();

Further details:

appellation commented 6 years ago

this seems related to #1870, as your error indicates that the client's GuildMember couldn't be resolved.

Yahweasel commented 6 years ago

I get this problem frequently as well. The problem is that resolver.resolveGuildMember is being passed something guild-flavored that is not the correct Guild object. The relevant call is VoiceChannel.joinable's getter, by way of GuildChannel.permissionsFor. resolveGuildMember resolves to null, breaking everything. Here's some info from a recent instance which may or may not be helpful:

> client.guilds.get("277565757078896640").channels.get("277565757553115136").guild === client.guilds.get("277565757078896640")
false

> client.guilds.get("277565757078896640").channels.get("277565757553115136").guild.id === client.guilds.get("277565757078896640").id
true

> client.guilds.get("277565757078896640").channels.get("277565757553115136").guild.constructor.name
Guild

I have no idea how the VoiceChannel has a guild reference to a semi-identical guild that is not the right guild, but that's the underlying problem.

I have temporarily replaced in GuildChannel.js:

    member = this.client.resolver.resolveGuildMember(this.guild, member);

with:

    member = this.client.resolver.resolveGuildMember(this.client.guilds.get(this.guild.id), member);

That's obviously nutty, but might work around the relevant caching and "fix" things. I'll report back if I see the bug again.

Yahweasel commented 6 years ago

That workaround didn't QUITE work, as it just pushed the problem to somewhere later, but this workaround (just before checking joinable or joining) appears to be working:

        try {
            var fguild = client.guilds.get(guild.id);
            if (fguild) {
                guild = fguild;
                var fchannel = guild.channels.get(channel.id);
                if (fchannel)
                    channel = fchannel;
                channel.guild = guild; // Unbelievably, we can do this!
            }
        } catch (ex) {
            logex(ex);
        }
Yahweasel commented 6 years ago

I've also added the following debugging code to the GuildChannel constructor:

    if (guild !== guild.client.guilds.get(guild.id))
        console.error(new Error("Guild mismatch").stack);

which has yielded the following stacktrace:

Error: Guild mismatch
    at new GuildChannel (/home/yahweasel/craig/node_modules/discord.js/src/structures/GuildChannel.js:17:23)
    at new VoiceChannel (/home/yahweasel/craig/node_modules/discord.js/src/structures/VoiceChannel.js:10:5)
    at ClientDataManager.newChannel (/home/yahweasel/craig/node_modules/discord.js/src/client/ClientDataManager.js:63:21)
    at ChannelCreateAction.handle (/home/yahweasel/craig/node_modules/discord.js/src/client/actions/ChannelCreate.js:6:40)
    at ChannelCreateHandler.handle (/home/yahweasel/craig/node_modules/discord.js/src/client/websocket/packets/handlers/ChannelCreate.js:7:34)
    at WebSocketPacketManager.handle (/home/yahweasel/craig/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:103:65)
    at WebSocketConnection.onPacket (/home/yahweasel/craig/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:330:35)
    at WebSocketConnection.onMessage (/home/yahweasel/craig/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:293:17)
    at WebSocketClient.internalOnMessage (/home/yahweasel/craig/node_modules/uws/uws.js:103:17)
    at native.client.group.onMessage (/home/yahweasel/craig/node_modules/uws/uws.js:57:15)

but looking through it, I found it incomprehensible that this error could arise, so I'm no further along.

DevYukine commented 6 years ago

@Yahweasel okay so i actuall like your debugging could you add a console.log and deeply log both Guild instances so we can compare what is actuall different? that may help

Yahweasel commented 6 years ago

I have added such a log line and will update once one fires.

Yahweasel commented 6 years ago

Embarrassingly, the case in the GuildChannel constructor just had client.guilds[id] as undefined, so obviously that was during some initial construction, before it had fully initialized. Whoops :)

I added the printout to my workaround before checking joinable, so this is immediately before trying to actually join the relevant channel, comparing client.guilds.get(channel.guild.id) (first) with channel.guild (second):

console.error output ``` vvvvv JOINABLE MISMATCH vvvvv Guild { members: Collection { '155149108183695360' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: '■', joinedTimestamp: 1516763463546, lastMessageID: null, lastMessage: null }, '159985870458322944' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: '■', joinedTimestamp: 1516748213148, lastMessageID: null, lastMessage: null }, '272937604339466240' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: null, joinedTimestamp: 1518564574335, lastMessageID: null, lastMessage: null }, '273887062086778880' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: false, selfDeaf: false, voiceSessionID: '5b073d07f6eb1141848002eb061ada0a', voiceChannelID: '405546647997644801', speaking: false, nickname: null, joinedTimestamp: 1518365932316, lastMessageID: null, lastMessage: null }, '280437402370179072' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: false, selfDeaf: false, voiceSessionID: '076bb740cc3d07fe603101c4dede0537', voiceChannelID: '405445689670369281', speaking: false, nickname: 'Relex [ YT ]', joinedTimestamp: 1516280340370, lastMessageID: null, lastMessage: null }, '335439077711020032' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: null, joinedTimestamp: 1518372312306, lastMessageID: null, lastMessage: null }, '359064367414771723' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: 'Nathan_BR', joinedTimestamp: 1517862123780, lastMessageID: null, lastMessage: null }, '369091837014573066' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: null, joinedTimestamp: 1518530768118, lastMessageID: null, lastMessage: null }, '384475855990161408' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: 'Pekenn0 [ Assistente ]', joinedTimestamp: 1517512697475, lastMessageID: null, lastMessage: null }, '403513400384159744' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: 'Pasz [ Admin ]', joinedTimestamp: 1516763614293, lastMessageID: null, lastMessage: null }, '405369863436238848' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: null, joinedTimestamp: 1518540261725, lastMessageID: null, lastMessage: null }, '405448463086649347' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: false, selfDeaf: false, voiceSessionID: '0954835234dd0f1ab3a7939377ddd2ec', voiceChannelID: '405445689670369281', speaking: false, nickname: 'Lordwzin [ Admin ]', joinedTimestamp: 1518365540894, lastMessageID: null, lastMessage: null } }, channels: Collection { '405444174670725140' => VoiceChannel { type: 'voice', id: '405444174670725140', name: '🎬 Sala 1', position: 8, parentID: '405444476513812490', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405444308603240449' => CategoryChannel { type: null, id: '405444308603240449', name: '🔐 Autorizados', position: 0, parentID: null, permissionOverwrites: [Object], guild: [Circular] }, '405444476513812490' => CategoryChannel { type: null, id: '405444476513812490', name: '🎥 Gravar', position: 1, parentID: null, permissionOverwrites: [Object], guild: [Circular] }, '405444566280568843' => VoiceChannel { type: 'voice', id: '405444566280568843', name: '🎬 Sala 2', position: 9, parentID: '405444476513812490', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405444732869804053' => VoiceChannel { type: 'voice', id: '405444732869804053', name: '🔹 Sala 1', position: 1, parentID: null, permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405444863061131285' => TextChannel { type: 'text', id: '405444863061131285', name: 'chat', position: 2, parentID: '405444476513812490', permissionOverwrites: [Object], topic: '', nsfw: false, lastMessageID: '411558090215915541', guild: [Circular], messages: Collection {}, _typing: Map {} }, '405445689670369281' => VoiceChannel { type: 'voice', id: '405445689670369281', name: 'Sala 1', position: 5, parentID: '405444308603240449', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: [Object] }, '405446837734998026' => VoiceChannel { type: 'voice', id: '405446837734998026', name: '⛔ ausentes', position: 4, parentID: null, permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405485703149912064' => VoiceChannel { type: 'voice', id: '405485703149912064', name: '🔹 Sala 2', position: 2, parentID: null, permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405485756950380544' => VoiceChannel { type: 'voice', id: '405485756950380544', name: '🔹 Sala-3', position: 3, parentID: null, permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405489244157509632' => VoiceChannel { type: 'voice', id: '405489244157509632', name: '🔒 Sala 2', position: 6, parentID: '405444308603240449', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405489275136638986' => VoiceChannel { type: 'voice', id: '405489275136638986', name: '🔒 Sala 3', position: 7, parentID: '405444308603240449', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405489652221345792' => VoiceChannel { type: 'voice', id: '405489652221345792', name: '🎬 Sala 3', position: 10, parentID: '405444476513812490', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405546647997644801' => VoiceChannel { type: 'voice', id: '405546647997644801', name: '🎵 Música 🎵', position: 0, parentID: null, permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: [Object] }, '405591345810374672' => VoiceChannel { type: 'voice', id: '405591345810374672', name: '👥 Participar', position: 11, parentID: '405444476513812490', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '409346825179365376' => TextChannel { type: 'text', id: '409346825179365376', name: 'log', position: 3, parentID: '405444308603240449', permissionOverwrites: [Object], topic: null, nsfw: false, lastMessageID: '413114185791176716', guild: [Circular], messages: Collection {}, _typing: Map {} }, '412283074445967361' => TextChannel { type: 'text', id: '412283074445967361', name: 'chat-principal', position: 4, parentID: null, permissionOverwrites: [Object], topic: null, nsfw: false, lastMessageID: '413107570270666752', guild: [Circular], messages: Collection {}, _typing: Map {} } }, roles: Collection { '403533737515679745' => Role { guild: [Circular], id: '403533737515679745', name: '@everyone', color: 0, hoist: false, position: 0, permissions: 0, managed: false, mentionable: false }, '405436316071886890' => Role { guild: [Circular], id: '405436316071886890', name: 'Youtuber', color: 16711680, hoist: false, position: 10, permissions: 104254529, managed: false, mentionable: true }, '405436768633094165' => Role { guild: [Circular], id: '405436768633094165', name: 'Assistente de Gravação', color: 16733525, hoist: false, position: 9, permissions: 37145665, managed: false, mentionable: false }, '405437596433514516' => Role { guild: [Circular], id: '405437596433514516', name: 'Dono', color: 7419530, hoist: true, position: 14, permissions: 2146958591, managed: false, mentionable: true }, '405437995890507776' => Role { guild: [Circular], id: '405437995890507776', name: 'Inscrito', color: 16776958, hoist: false, position: 6, permissions: 37198913, managed: false, mentionable: false }, '405447092635697165' => Role { guild: [Circular], id: '405447092635697165', name: 'Admin', color: 11010151, hoist: true, position: 13, permissions: 2146958591, managed: false, mentionable: true }, '405496138414817280' => Role { guild: [Circular], id: '405496138414817280', name: 'Mee6', color: 0, hoist: false, position: 4, permissions: 66583679, managed: true, mentionable: false }, '405522061671530496' => Role { guild: [Circular], id: '405522061671530496', name: 'Muted', color: 8487814, hoist: false, position: 3, permissions: 1048576, managed: false, mentionable: true }, '405525523708641283' => Role { guild: [Circular], id: '405525523708641283', name: 'Bots', color: 196608, hoist: true, position: 5, permissions: 8, managed: false, mentionable: false }, '405551451163721738' => Role { guild: [Circular], id: '405551451163721738', name: 'Ajudante', color: 16773376, hoist: true, position: 11, permissions: 108321857, managed: false, mentionable: false }, '405560103199178753' => Role { guild: [Circular], id: '405560103199178753', name: 'Dyno', color: 0, hoist: false, position: 8, permissions: 2134207743, managed: true, mentionable: false }, '405893846682173440' => Role { guild: [Circular], id: '405893846682173440', name: 'Youtuber / Dono', color: 62975, hoist: true, position: 15, permissions: 2146958591, managed: false, mentionable: false }, '407731574277275648' => Role { guild: [Circular], id: '407731574277275648', name: 'Moderador', color: 65379, hoist: true, position: 12, permissions: 104324161, managed: false, mentionable: false }, '411550529563525130' => Role { guild: [Circular], id: '411550529563525130', name: 'inscrito+', color: 15323477, hoist: false, position: 7, permissions: 104324161, managed: false, mentionable: false }, '412281344421265408' => Role { guild: [Circular], id: '412281344421265408', name: 'Lado Negro🎶', color: 0, hoist: false, position: 2, permissions: 133692568, managed: true, mentionable: false }, '413114509574537226' => Role { guild: [Circular], id: '413114509574537226', name: 'Craig', color: 0, hoist: false, position: 1, permissions: 68160520, managed: true, mentionable: false } }, presences: Collection { '155149108183695360' => Presence { status: 'online', game: [Object] }, '159985870458322944' => Presence { status: 'online', game: [Object] }, '272937604339466240' => Presence { status: 'online', game: [Object] }, '273887062086778880' => Presence { status: 'online', game: null }, '280437402370179072' => Presence { status: 'online', game: [Object] }, '405448463086649347' => Presence { status: 'dnd', game: [Object] } }, name: 'TeamRelex', icon: '0291d74472fce4e54911ecfc579e2272', splash: null, region: 'brazil', memberCount: 12, large: false, features: [], applicationID: null, afkTimeout: 300, afkChannelID: '405446837734998026', systemChannelID: null, embedEnabled: undefined, verificationLevel: 0, explicitContentFilter: 1, joinedTimestamp: 1518564574335, id: '403533737515679745', available: true, ownerID: '280437402370179072', _rawVoiceStates: Collection { '273887062086778880' => { channel_id: '405546647997644801', deaf: false, mute: false, self_deaf: false, self_mute: false, self_video: false, session_id: '5b073d07f6eb1141848002eb061ada0a', suppress: false, user_id: '273887062086778880' }, '280437402370179072' => { channel_id: '405445689670369281', deaf: false, mute: false, self_deaf: false, self_mute: false, self_video: false, session_id: '076bb740cc3d07fe603101c4dede0537', suppress: false, user_id: '280437402370179072' }, '405448463086649347' => { channel_id: '405445689670369281', deaf: false, mute: false, self_deaf: false, self_mute: false, self_video: false, session_id: '0954835234dd0f1ab3a7939377ddd2ec', suppress: false, user_id: '405448463086649347' } }, emojis: Collection {} } Guild { members: Collection { '155149108183695360' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: '■', joinedTimestamp: 1516763463546, lastMessageID: null, lastMessage: null }, '159985870458322944' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: '■', joinedTimestamp: 1516748213148, lastMessageID: '413107570270666752', lastMessage: [Object] }, '273887062086778880' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: false, selfDeaf: false, voiceSessionID: '5b073d07f6eb1141848002eb061ada0a', voiceChannelID: '405546647997644801', speaking: false, nickname: null, joinedTimestamp: 1518365932316, lastMessageID: null, lastMessage: null }, '280437402370179072' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: false, selfDeaf: false, voiceSessionID: '076bb740cc3d07fe603101c4dede0537', voiceChannelID: '405445689670369281', speaking: false, nickname: 'Relex [ YT ]', joinedTimestamp: 1516280340370, lastMessageID: '413114997233811468', lastMessage: [Object] }, '335439077711020032' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: null, joinedTimestamp: 1518372312306, lastMessageID: null, lastMessage: null }, '359064367414771723' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: true, selfDeaf: false, voiceSessionID: '30c620b7330d6bbfbee8aa1bd34bf128', voiceChannelID: null, speaking: null, nickname: 'Nathan_BR', joinedTimestamp: 1517862123780, lastMessageID: null, lastMessage: null }, '369091837014573066' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: null, joinedTimestamp: 1518530768118, lastMessageID: null, lastMessage: null }, '384475855990161408' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: 'Pekenn0 [ Assistente ]', joinedTimestamp: 1517512697475, lastMessageID: null, lastMessage: null }, '403513400384159744' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: 'Pasz [ Admin ]', joinedTimestamp: 1516763614293, lastMessageID: null, lastMessage: null }, '405369863436238848' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: undefined, selfDeaf: undefined, voiceSessionID: undefined, voiceChannelID: undefined, speaking: false, nickname: null, joinedTimestamp: 1518540261725, lastMessageID: null, lastMessage: null }, '405448463086649347' => GuildMember { guild: [Circular], user: [Object], _roles: [Array], serverDeaf: false, serverMute: false, selfMute: false, selfDeaf: false, voiceSessionID: '0954835234dd0f1ab3a7939377ddd2ec', voiceChannelID: '405445689670369281', speaking: null, nickname: 'Lordwzin [ Admin ]', joinedTimestamp: 1518365540894, lastMessageID: '413107567951216680', lastMessage: [Object] } }, channels: Collection { '405444174670725140' => VoiceChannel { type: 'voice', id: '405444174670725140', name: '🎬 Sala 1', position: 8, parentID: '405444476513812490', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405444308603240449' => CategoryChannel { type: null, id: '405444308603240449', name: '🔐 Autorizados', position: 0, parentID: null, permissionOverwrites: [Object], guild: [Circular] }, '405444476513812490' => CategoryChannel { type: null, id: '405444476513812490', name: '🎥 Gravar', position: 1, parentID: null, permissionOverwrites: [Object], guild: [Circular] }, '405444566280568843' => VoiceChannel { type: 'voice', id: '405444566280568843', name: '🎬 Sala 2', position: 9, parentID: '405444476513812490', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405444732869804053' => VoiceChannel { type: 'voice', id: '405444732869804053', name: '🔹 Sala 1', position: 1, parentID: null, permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: [Object] }, '405444863061131285' => TextChannel { type: 'text', id: '405444863061131285', name: 'chat', position: 2, parentID: '405444476513812490', permissionOverwrites: [Object], topic: '', nsfw: false, lastMessageID: '411558090215915541', guild: [Circular], messages: Collection {}, _typing: Map {} }, '405445689670369281' => VoiceChannel { type: 'voice', id: '405445689670369281', name: 'Sala 1', position: 5, parentID: '405444308603240449', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: [Object] }, '405446837734998026' => VoiceChannel { type: 'voice', id: '405446837734998026', name: '⛔ ausentes', position: 4, parentID: null, permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405485703149912064' => VoiceChannel { type: 'voice', id: '405485703149912064', name: '🔹 Sala 2', position: 2, parentID: null, permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405485756950380544' => VoiceChannel { type: 'voice', id: '405485756950380544', name: '🔹 Sala-3', position: 3, parentID: null, permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405489244157509632' => VoiceChannel { type: 'voice', id: '405489244157509632', name: '🔒 Sala 2', position: 6, parentID: '405444308603240449', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405489275136638986' => VoiceChannel { type: 'voice', id: '405489275136638986', name: '🔒 Sala 3', position: 7, parentID: '405444308603240449', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405489652221345792' => VoiceChannel { type: 'voice', id: '405489652221345792', name: '🎬 Sala 3', position: 10, parentID: '405444476513812490', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '405546647997644801' => VoiceChannel { type: 'voice', id: '405546647997644801', name: '🎵 Música 🎵', position: 0, parentID: null, permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: [Object] }, '405591345810374672' => VoiceChannel { type: 'voice', id: '405591345810374672', name: '👥 Participar', position: 11, parentID: '405444476513812490', permissionOverwrites: [Object], bitrate: 64, userLimit: 0, guild: [Circular], members: Collection {} }, '409346825179365376' => TextChannel { type: 'text', id: '409346825179365376', name: 'log', position: 3, parentID: '405444308603240449', permissionOverwrites: [Object], topic: null, nsfw: false, lastMessageID: '413114997233811468', guild: [Circular], messages: [Object], _typing: [Object], lastMessage: [Object] }, '412283074445967361' => TextChannel { type: 'text', id: '412283074445967361', name: 'chat-principal', position: 4, parentID: null, permissionOverwrites: [Object], topic: null, nsfw: false, lastMessageID: '413107570270666752', guild: [Circular], messages: [Object], _typing: Map {}, lastMessage: [Object] } }, roles: Collection { '403533737515679745' => Role { guild: [Circular], id: '403533737515679745', name: '@everyone', color: 0, hoist: false, position: 0, permissions: 0, managed: false, mentionable: false }, '405436316071886890' => Role { guild: [Circular], id: '405436316071886890', name: 'Youtuber', color: 16711680, hoist: false, position: 10, permissions: 104254529, managed: false, mentionable: true }, '405436768633094165' => Role { guild: [Circular], id: '405436768633094165', name: 'Assistente de Gravação', color: 16733525, hoist: false, position: 9, permissions: 37145665, managed: false, mentionable: false }, '405437596433514516' => Role { guild: [Circular], id: '405437596433514516', name: 'Dono', color: 7419530, hoist: true, position: 14, permissions: 2146958591, managed: false, mentionable: true }, '405437995890507776' => Role { guild: [Circular], id: '405437995890507776', name: 'Inscrito', color: 16776958, hoist: false, position: 6, permissions: 37198913, managed: false, mentionable: false }, '405447092635697165' => Role { guild: [Circular], id: '405447092635697165', name: 'Admin', color: 11010151, hoist: true, position: 13, permissions: 2146958591, managed: false, mentionable: true }, '405496138414817280' => Role { guild: [Circular], id: '405496138414817280', name: 'Mee6', color: 0, hoist: false, position: 4, permissions: 66583679, managed: true, mentionable: false }, '405522061671530496' => Role { guild: [Circular], id: '405522061671530496', name: 'Muted', color: 8487814, hoist: false, position: 3, permissions: 1048576, managed: false, mentionable: true }, '405525523708641283' => Role { guild: [Circular], id: '405525523708641283', name: 'Bots', color: 196608, hoist: true, position: 5, permissions: 8, managed: false, mentionable: false }, '405551451163721738' => Role { guild: [Circular], id: '405551451163721738', name: 'Ajudante', color: 16773376, hoist: true, position: 11, permissions: 108321857, managed: false, mentionable: false }, '405560103199178753' => Role { guild: [Circular], id: '405560103199178753', name: 'Dyno', color: 0, hoist: false, position: 8, permissions: 2134207743, managed: true, mentionable: false }, '405893846682173440' => Role { guild: [Circular], id: '405893846682173440', name: 'Youtuber / Dono', color: 62975, hoist: true, position: 15, permissions: 2146958591, managed: false, mentionable: false }, '407731574277275648' => Role { guild: [Circular], id: '407731574277275648', name: 'Moderador', color: 65379, hoist: true, position: 12, permissions: 104324161, managed: false, mentionable: false }, '411550529563525130' => Role { guild: [Circular], id: '411550529563525130', name: 'inscrito+', color: 15323477, hoist: false, position: 7, permissions: 104324161, managed: false, mentionable: false }, '412281344421265408' => Role { guild: [Circular], id: '412281344421265408', name: 'Lado Negro🎶', color: 0, hoist: false, position: 1, permissions: 133692568, managed: true, mentionable: false } }, presences: Collection { '155149108183695360' => Presence { status: 'online', game: [Object] }, '159985870458322944' => Presence { status: 'online', game: [Object] }, '272937604339466240' => Presence { status: 'online', game: [Object] }, '273887062086778880' => Presence { status: 'online', game: null }, '280437402370179072' => Presence { status: 'online', game: [Object] }, '280438940643885057' => Presence { status: 'offline', game: null }, '359064367414771723' => Presence { status: 'offline', game: null }, '384475855990161408' => Presence { status: 'offline', game: null }, '405448463086649347' => Presence { status: 'dnd', game: [Object] } }, available: true, id: '403533737515679745', name: 'TeamRelex', icon: '0291d74472fce4e54911ecfc579e2272', splash: null, region: 'brazil', memberCount: 11, large: false, features: [], applicationID: null, afkTimeout: 300, afkChannelID: '405446837734998026', systemChannelID: null, embedEnabled: undefined, verificationLevel: 0, explicitContentFilter: 1, joinedTimestamp: 1517931454421, ownerID: '280437402370179072', _rawVoiceStates: Collection { '273887062086778880' => { channel_id: '405546647997644801', deaf: false, mute: false, self_deaf: false, self_mute: false, self_video: false, session_id: '5b073d07f6eb1141848002eb061ada0a', suppress: false, user_id: '273887062086778880' }, '280437402370179072' => { channel_id: '405546647997644801', deaf: false, mute: false, self_deaf: false, self_mute: false, self_video: false, session_id: '076bb740cc3d07fe603101c4dede0537', suppress: false, user_id: '280437402370179072' }, '280438940643885057' => { channel_id: '405546647997644801', deaf: false, mute: false, self_deaf: false, self_mute: false, self_video: false, session_id: '2764326ae9ae3407197e01ed3eba80d9', suppress: false, user_id: '280438940643885057' }, '359064367414771723' => { channel_id: '405546647997644801', deaf: false, mute: false, self_deaf: false, self_mute: true, self_video: false, session_id: '30c620b7330d6bbfbee8aa1bd34bf128', suppress: false, user_id: '359064367414771723' }, '405448463086649347' => { channel_id: '405546647997644801', deaf: false, mute: false, self_deaf: false, self_mute: false, self_video: false, session_id: '6e1d38dc44815db88020e6964a409ef1', suppress: false, user_id: '405448463086649347' } }, emojis: Collection {} } ^^^^^ ```
Yahweasel commented 6 years ago

For what it's worth, the diff between the two guilds above:

guild diff ```diff --- a.txt 2018-02-13 19:24:55.340550668 -0500 +++ b.txt 2018-02-13 19:25:02.308615046 -0500 @@ -29,23 +29,8 @@ speaking: false, nickname: '■', joinedTimestamp: 1516748213148, - lastMessageID: null, - lastMessage: null }, - '272937604339466240' => GuildMember { - guild: [Circular], - user: [Object], - _roles: [Array], - serverDeaf: false, - serverMute: false, - selfMute: undefined, - selfDeaf: undefined, - voiceSessionID: undefined, - voiceChannelID: undefined, - speaking: false, - nickname: null, - joinedTimestamp: 1518564574335, - lastMessageID: null, - lastMessage: null }, + lastMessageID: '413107570270666752', + lastMessage: [Object] }, '273887062086778880' => GuildMember { guild: [Circular], user: [Object], @@ -74,8 +59,8 @@ speaking: false, nickname: 'Relex [ YT ]', joinedTimestamp: 1516280340370, - lastMessageID: null, - lastMessage: null }, + lastMessageID: '413114997233811468', + lastMessage: [Object] }, '335439077711020032' => GuildMember { guild: [Circular], user: [Object], @@ -97,11 +82,11 @@ _roles: [Array], serverDeaf: false, serverMute: false, - selfMute: undefined, - selfDeaf: undefined, - voiceSessionID: undefined, - voiceChannelID: undefined, - speaking: false, + selfMute: true, + selfDeaf: false, + voiceSessionID: '30c620b7330d6bbfbee8aa1bd34bf128', + voiceChannelID: null, + speaking: null, nickname: 'Nathan_BR', joinedTimestamp: 1517862123780, lastMessageID: null, @@ -176,11 +161,11 @@ selfDeaf: false, voiceSessionID: '0954835234dd0f1ab3a7939377ddd2ec', voiceChannelID: '405445689670369281', - speaking: false, + speaking: null, nickname: 'Lordwzin [ Admin ]', joinedTimestamp: 1518365540894, - lastMessageID: null, - lastMessage: null } }, + lastMessageID: '413107567951216680', + lastMessage: [Object] } }, channels: Collection { '405444174670725140' => VoiceChannel { @@ -231,7 +216,7 @@ bitrate: 64, userLimit: 0, guild: [Circular], - members: Collection {} }, + members: [Object] }, '405444863061131285' => TextChannel { type: 'text', id: '405444863061131285', @@ -353,10 +338,11 @@ permissionOverwrites: [Object], topic: null, nsfw: false, - lastMessageID: '413114185791176716', + lastMessageID: '413114997233811468', guild: [Circular], - messages: Collection {}, - _typing: Map {} }, + messages: [Object], + _typing: [Object], + lastMessage: [Object] }, '412283074445967361' => TextChannel { type: 'text', id: '412283074445967361', @@ -368,8 +354,9 @@ nsfw: false, lastMessageID: '413107570270666752', guild: [Circular], - messages: Collection {}, - _typing: Map {} } }, + messages: [Object], + _typing: Map {}, + lastMessage: [Object] } }, roles: Collection { '403533737515679745' => Role { @@ -518,18 +505,8 @@ name: 'Lado Negro🎶', color: 0, hoist: false, - position: 2, - permissions: 133692568, - managed: true, - mentionable: false }, - '413114509574537226' => Role { - guild: [Circular], - id: '413114509574537226', - name: 'Craig', - color: 0, - hoist: false, position: 1, - permissions: 68160520, + permissions: 133692568, managed: true, mentionable: false } }, presences: @@ -539,12 +516,17 @@ '272937604339466240' => Presence { status: 'online', game: [Object] }, '273887062086778880' => Presence { status: 'online', game: null }, '280437402370179072' => Presence { status: 'online', game: [Object] }, + '280438940643885057' => Presence { status: 'offline', game: null }, + '359064367414771723' => Presence { status: 'offline', game: null }, + '384475855990161408' => Presence { status: 'offline', game: null }, '405448463086649347' => Presence { status: 'dnd', game: [Object] } }, + available: true, + id: '403533737515679745', name: 'TeamRelex', icon: '0291d74472fce4e54911ecfc579e2272', splash: null, region: 'brazil', - memberCount: 12, + memberCount: 11, large: false, features: [], applicationID: null, @@ -554,9 +536,7 @@ embedEnabled: undefined, verificationLevel: 0, explicitContentFilter: 1, - joinedTimestamp: 1518564574335, - id: '403533737515679745', - available: true, + joinedTimestamp: 1517931454421, ownerID: '280437402370179072', _rawVoiceStates: Collection { @@ -569,7 +549,7 @@ session_id: '5b073d07f6eb1141848002eb061ada0a', suppress: false, user_id: '273887062086778880' }, - '280437402370179072' => { channel_id: '405445689670369281', + '280437402370179072' => { channel_id: '405546647997644801', deaf: false, mute: false, self_deaf: false, @@ -578,13 +558,31 @@ session_id: '076bb740cc3d07fe603101c4dede0537', suppress: false, user_id: '280437402370179072' }, - '405448463086649347' => { channel_id: '405445689670369281', + '280438940643885057' => { channel_id: '405546647997644801', + deaf: false, + mute: false, + self_deaf: false, + self_mute: false, + self_video: false, + session_id: '2764326ae9ae3407197e01ed3eba80d9', + suppress: false, + user_id: '280438940643885057' }, + '359064367414771723' => { channel_id: '405546647997644801', + deaf: false, + mute: false, + self_deaf: false, + self_mute: true, + self_video: false, + session_id: '30c620b7330d6bbfbee8aa1bd34bf128', + suppress: false, + user_id: '359064367414771723' }, + '405448463086649347' => { channel_id: '405546647997644801', deaf: false, mute: false, self_deaf: false, self_mute: false, self_video: false, - session_id: '0954835234dd0f1ab3a7939377ddd2ec', + session_id: '6e1d38dc44815db88020e6964a409ef1', suppress: false, user_id: '405448463086649347' } }, emojis: Collection {} } ```
Yahweasel commented 6 years ago

I'm not confident of this, but it seems that sometimes when the workaround is in place (replacing channel.guild with client.guilds.get(channel.guild.id)), the bot doesn't correctly join the voice channel. join succeeds, the VoiceConnection seems to work, but it simply never fires any opus events. This doesn't ALWAYS happen with that workaround, however. I've adjusted the workaround in my bot so it only fires if joinable threw an exception in the first place.

amishshah commented 6 years ago

Hi, is this still occurring?

amishshah commented 6 years ago

Going to close this issue, if someone can reproduce this we'll investigate again.

elliopitas commented 4 years ago

happens to mee too @amishshah I used this line to connect just like in the guide

const connection = await USER.member.voice.channel.join();

and i get

TypeError: Cannot read property 'join' of null
    at Object.execute (A:\programing\javascript\ARXIDOPRIXTIS\spastikovoice.js:6:64)
    at Client.<anonymous> (A:\programing\javascript\ARXIDOPRIXTIS\index.js:57:23)
    at Client.emit (events.js:321:20)
    at VoiceStateUpdate.handle (A:\programing\javascript\ARXIDOPRIXTIS\node_modules\discord.js\src\client\actions\VoiceStateUpdate.js:39:14)
    at Object.module.exports [as VOICE_STATE_UPDATE] (A:\programing\javascript\ARXIDOPRIXTIS\node_modules\discord.js\src\client\websocket\handlers\VOICE_STATE_UPDATE.js:4:35)
    at WebSocketManager.handlePacket (A:\programing\javascript\ARXIDOPRIXTIS\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (A:\programing\javascript\ARXIDOPRIXTIS\node_modules\discord.js\src\client\websocket\WebSocketShard.js:437:22)
    at WebSocketShard.onMessage (A:\programing\javascript\ARXIDOPRIXTIS\node_modules\discord.js\src\client\websocket\WebSocketShard.js:295:10)
    at WebSocket.onMessage (A:\programing\javascript\ARXIDOPRIXTIS\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:321:20)

btw USER is a voice state object

discord.js@12.0.0-dev (github:discordjs/discord.js#bea6da621d0e37000826c6fddf6f33c964704443) Node.js v13.8.0. full code to reproduce index.js

const spastikovoice= require(`./spastikovoice.js`);
client.on("voiceStateUpdate",async (USERoldState,USER) => {
        spastikovoice.execute(USERoldState,USER);
});

spastikovoice.js

const fs = require('fs');

module.exports= {
    async execute(USERoldState, USER) {
        try {
            const connection = await USER.member.voice.channel.join();
            if (!USERoldState.channelID) { //joins channel
                //const dispatcher =connection.play(fs.createReadStream('/programing/javascript/ARXIDOPRIXTIS/audio/hmmmm.ogg'), { type: 'ogg/opus' }); //from docker /usr/src/audio/hmmmm.ogg
                const dispatcher = connection.play(fs.createReadStream('audio/hmmmm.ogg'), {type: 'ogg/opus'}); //from docker /usr/src/audio/hmmmo.ogg //from desktop /programing/javascript/ARXIDOPRIXTIS/audio/hmmmo.ogg
                dispatcher.on('start', () => {
                    console.log('audio is now playing!');
                });
                dispatcher.on('finish', () => {
                    console.log('audio has finished playing!');
                    return connection.disconnect();
                });
                dispatcher.on('error', console.error);
            } else if (!USER.channelID) {
                console.log("left");
                const dispatcher = connection.play(fs.createReadStream('audio/hmmmmleft.ogg'), {type: 'ogg/opus'});
                dispatcher.on('start', () => {
                    console.log('audio is now playing!');
                });
                dispatcher.on('finish', () => {
                    console.log('audio has finished playing!');
                    return connection.disconnect().catch(error=>{console.error(error)});
                });
                dispatcher.on('error', console.error);
            }

        } catch (error) {
            console.error(error);
        }
    }
}
elliopitas commented 4 years ago

happens to mee too @amishshah I used this line to connect just like in the guide

const connection = await USER.member.voice.channel.join();

and i get

TypeError: Cannot read property 'join' of null
    at Object.execute (A:\programing\javascript\ARXIDOPRIXTIS\spastikovoice.js:6:64)
    at Client.<anonymous> (A:\programing\javascript\ARXIDOPRIXTIS\index.js:57:23)
    at Client.emit (events.js:321:20)
    at VoiceStateUpdate.handle (A:\programing\javascript\ARXIDOPRIXTIS\node_modules\discord.js\src\client\actions\VoiceStateUpdate.js:39:14)
    at Object.module.exports [as VOICE_STATE_UPDATE] (A:\programing\javascript\ARXIDOPRIXTIS\node_modules\discord.js\src\client\websocket\handlers\VOICE_STATE_UPDATE.js:4:35)
    at WebSocketManager.handlePacket (A:\programing\javascript\ARXIDOPRIXTIS\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (A:\programing\javascript\ARXIDOPRIXTIS\node_modules\discord.js\src\client\websocket\WebSocketShard.js:437:22)
    at WebSocketShard.onMessage (A:\programing\javascript\ARXIDOPRIXTIS\node_modules\discord.js\src\client\websocket\WebSocketShard.js:295:10)
    at WebSocket.onMessage (A:\programing\javascript\ARXIDOPRIXTIS\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:321:20)

btw USER is a voice state object

discord.js@12.0.0-dev (github:discordjs/discord.js#bea6da621d0e37000826c6fddf6f33c964704443) Node.js v13.8.0. full code to reproduce index.js

const spastikovoice= require(`./spastikovoice.js`);
client.on("voiceStateUpdate",async (USERoldState,USER) => {
        spastikovoice.execute(USERoldState,USER);
});

spastikovoice.js

const fs = require('fs');

module.exports= {
    async execute(USERoldState, USER) {
        try {
            const connection = await USER.member.voice.channel.join();
            if (!USERoldState.channelID) { //joins channel
                //const dispatcher =connection.play(fs.createReadStream('/programing/javascript/ARXIDOPRIXTIS/audio/hmmmm.ogg'), { type: 'ogg/opus' }); //from docker /usr/src/audio/hmmmm.ogg
                const dispatcher = connection.play(fs.createReadStream('audio/hmmmm.ogg'), {type: 'ogg/opus'}); //from docker /usr/src/audio/hmmmo.ogg //from desktop /programing/javascript/ARXIDOPRIXTIS/audio/hmmmo.ogg
                dispatcher.on('start', () => {
                    console.log('audio is now playing!');
                });
                dispatcher.on('finish', () => {
                    console.log('audio has finished playing!');
                    return connection.disconnect();
                });
                dispatcher.on('error', console.error);
            } else if (!USER.channelID) {
                console.log("left");
                const dispatcher = connection.play(fs.createReadStream('audio/hmmmmleft.ogg'), {type: 'ogg/opus'});
                dispatcher.on('start', () => {
                    console.log('audio is now playing!');
                });
                dispatcher.on('finish', () => {
                    console.log('audio has finished playing!');
                    return connection.disconnect().catch(error=>{console.error(error)});
                });
                dispatcher.on('error', console.error);
            }

        } catch (error) {
            console.error(error);
        }
    }
}

fixed it by adding this in index.js

if(USER.member.voice.channel!==null){
        spastikovoice.join(USER);
   }