[SOLVED] 🤦Bot doesnt join the voice channel

So I have the following code, when its being executed, the bot doesnt join the voice channel.
const { joinVoiceChannel, createAudioPlayer, createAudioResource, StreamType } = require("@discordjs/voice")
const { join } = require("node:path")

module.exports.run = async (message, client) => {

const resource = createAudioResource(join(__dirname, "pregame.wav"), {
inputType: StreamType.WebmOpus
})

const connection = joinVoiceChannel({
channelId: client.channelId,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
})

const player = createAudioPlayer()

player.play(resource)
connection.subscribe(player)

}
const { joinVoiceChannel, createAudioPlayer, createAudioResource, StreamType } = require("@discordjs/voice")
const { join } = require("node:path")

module.exports.run = async (message, client) => {

const resource = createAudioResource(join(__dirname, "pregame.wav"), {
inputType: StreamType.WebmOpus
})

const connection = joinVoiceChannel({
channelId: client.channelId,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
})

const player = createAudioPlayer()

player.play(resource)
connection.subscribe(player)

}
client.channelId is defined in the main file as a channel ID. Am i doing something wrong? There are no errors in the console and the file is being ran (ive added console.logs to see if it works and it does). Idk if its an intent issue but here are my intents:
const intents = [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMessages]
const intents = [GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMessages]
10 Replies
d.js toolkit
d.js toolkit•2y 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.
Ashish
AshishOP•2y ago
discord.js version is 14.11.0 and @discordjs/voice is 0.16.0 Also if the resource can't be created (like if the file doesn't exist), would it throw an error?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Ashish
AshishOP•2y ago
The command isn't being ran in a voice channel. client.channelId is the voice ID copy pasted from discord. (yes it's a string) Can anyone help me? The bot isnt joining the voice channel at all. Am i suppose to do anything else? The voice channel ID is correct, there are no errors at all, and the code above is what I have that I'm trying to get it to work. The file runs but the bot doesnt join the voice channel If it helps im trying to play a local file
duck
duck•2y ago
how are you confirming the id is correct? if you log client.channels.cache.get(client.channelId) do you receive the channel object? how have you confirmed that this executes in the first place? could you listen to the debug and error events on your connection and log the results? and side question, why are you specifying WebmOpus for your stream type?
d.js docs
d.js docs•2y ago
To debug your voice connection and player: • Use debug: true when creating your VoiceConnection and AudioPlayer • Add an event listener to the <VoiceConnection> and the <AudioPlayer>:
// Add one for each class if applicable
<AudioPlayer | VoiceConnection>
.on('debug', console.log)
.on('error', console.error)
// Add one for each class if applicable
<AudioPlayer | VoiceConnection>
.on('debug', console.log)
.on('error', console.error)
• Add an error listener to the stream you are passing to the resource:
<Stream>.on('error', console.error)
<Stream>.on('error', console.error)
Note: The <> represents classes that need to be adapted to their respective name in your code
Ashish
AshishOP•2y ago
Oh my God... That was the issue I was using the wrong property It was supposed to be client.voiceChannel... I am so sorry for wasting your time But may I ask, shouldn't it throw an error if the channel is not found? Or can I suggest this?
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
duck
duck•2y ago
@discordjs/voice doesn't resolve the channel id to a Channel object through discord.js before attempting to connect since it's intended to be standalone and usable with libraries other than discord.js beyond that, dapi doesn't send an error (or any response for that matter) for an invalid channel id in the initial voice state update, so there isn't really a way to distinguish the channel id being incorrect from the connection simply timing out it would be far easier for you to validate the id and realistically you should also handle the connection timing out
Ashish
AshishOP•2y ago
Got it đź‘Ť I guess I should resolve the channel id into a channel object and access the Id from there to ensure that the channel does exist
Want results from more Discord servers?
Add your server