Closed FireController1847 closed 6 years ago
this seems related to #1870, as your error indicates that the client's GuildMember
couldn't be resolved.
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.
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);
}
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.
@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
I have added such a log line and will update once one fires.
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):
For what it's worth, the diff between the two guilds above:
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.
Hi, is this still occurring?
Going to close this issue, if someone can reproduce this we'll investigate again.
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);
}
}
}
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);
}
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.
Include a reproducible code sample here, if possible:
Further details: