I am trying to add a command, that allows the creation of temporary voice channels.
I have created a new client within this command to try and get the joinVoiceChannel() params another way.
File:
const { joinVoiceChannel } = require ('@discordjs/voice')
module.exports = {
emoji: '๐',
name: 'voice',
description: 'Create a temporary voice channel',
execute(interaction) {
console.log('hi')
joinVoiceChannel({
channelId: interaction.channel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
})
}
}
Error:
TypeError: Cannot read property 'id' of undefined
at Object.execute (C:\Users\tomfi\Code\DiscordBot\commands\voice.js:11:38)
at module.exports (C:\Users\tomfi\Code\DiscordBot\events\messageCreate.js:16:17)
at Client.emit (node:events:394:28)
at MessageCreateAction.handle (C:\Users\tomfi\Code\DiscordBot\node_modules\discord.js\src\client\actions\MessageCreate.js:23:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\tomfi\Code\DiscordBot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\tomfi\Code\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:345:31)
at WebSocketShard.onPacket (C:\Users\tomfi\Code\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:443:22)
at WebSocketShard.onMessage (C:\Users\tomfi\Code\DiscordBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:300:10)
at WebSocket.onMessage (C:\Users\tomfi\Code\DiscordBot\node_modules\ws\lib\event-target.js:132:16)
at WebSocket.emit (node:events:394:28)
joinVoiceChannel does not create a voice channel, it creates a voice connection. You need to use GuildChannelManager.create instead. Here is how:
const channel = await interaction.guild.channels.create("VC_NAME", {
type: "GUILD_VOICE" //note it is "GUILD_VOICE" and not just "voice" anymore
}
joinVoiceChannel({
channelId: channel.id,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator,
})