Somehow getVoiceConnection(guildId) returns undefined

Well, as the title already says, Somehow getVoiceConnection(guildId) returns undefined. I'm following this tutorial: https://youtu.be/oRWAuXqCuYA?t=841 (Timestamp is where the function is used). Node v16.14.2 discord.js v14.0.3 discordjs/voice v0.11.0
Tomato6966
YouTube
How To Make An ADVANCED Discord Music Bot - #03 - VoiceConnections ...
How To Make A Discord Bot! Music bots are one of the most fun discord bots to code and maintain! In this video, we use all new discord js v13 code to create an amazing discord music bot with join, skip, queue, stop, filters, bassboost, nightcore, speed, slash Commands and Text Commands!. This is an advanced tutorial if you are having difficultie...
2 Replies
d.js docs
d.js docs3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
ncls.
ncls.OP3y ago
I just found out that the check for if it has permissions doesn't seem to work. It then wants to output an error message but that message uses the oldConnection variable and therefor fails to send the message. So my actual issue is the checking for permission. Code:
if (!message.member.voice.channel?.permissionsFor(message.guild.me)?.has(Permissions.FLAGS.CONNECT)) {
return message.reply({ content: `❌ Ich habe keine Berechtigung, <#${oldConnection.joinConfig.channelId}> beizutreten.` }).catch(() => null);
}

if (!message.member.voice.channel?.permissionsFor(message.guild.me)?.has(Permissions.FLAGS.SPEAK)) {
return message.reply({ content: `❌ Ich habe keine Berechtigung, in <#${oldConnection.joinConfig.channelId}> zu reden.` }).catch(() => null);
}
if (!message.member.voice.channel?.permissionsFor(message.guild.me)?.has(Permissions.FLAGS.CONNECT)) {
return message.reply({ content: `❌ Ich habe keine Berechtigung, <#${oldConnection.joinConfig.channelId}> beizutreten.` }).catch(() => null);
}

if (!message.member.voice.channel?.permissionsFor(message.guild.me)?.has(Permissions.FLAGS.SPEAK)) {
return message.reply({ content: `❌ Ich habe keine Berechtigung, in <#${oldConnection.joinConfig.channelId}> zu reden.` }).catch(() => null);
}
Thought so... It recognized "Permissions" as class in VSC but now I'm looking in the docs and can't find a permission class in v14. Found the PermissionsBitField you just wrote Yeah, so this worked perfectly now. Thank you. I'm just asking myself if the error messages make sense then... Because if oldConnection is the connection the bot has right now, it will always be undefined if the bot can't join, meaning the error message will never show up like this... Ok, I'm just dumb. I actually implemented that part and I wasn't thinking right. Thanks for your help!
Want results from more Discord servers?
Add your server