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:UserstomfiCodeDiscordBotcommandsvoice.js:11:38)
at module.exports (C:UserstomfiCodeDiscordBoteventsmessageCreate.js:16:17)
at Client.emit (node:events:394:28)
at MessageCreateAction.handle (C:UserstomfiCodeDiscordBotnode_modulesdiscord.jssrcclientactionsMessageCreate.js:23:14)
at Object.module.exports [as MESSAGE_CREATE] (C:UserstomfiCodeDiscordBotnode_modulesdiscord.jssrcclientwebsockethandlersMESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:UserstomfiCodeDiscordBotnode_modulesdiscord.jssrcclientwebsocketWebSocketManager.js:345:31)
at WebSocketShard.onPacket (C:UserstomfiCodeDiscordBotnode_modulesdiscord.jssrcclientwebsocketWebSocketShard.js:443:22)
at WebSocketShard.onMessage (C:UserstomfiCodeDiscordBotnode_modulesdiscord.jssrcclientwebsocketWebSocketShard.js:300:10)
at WebSocket.onMessage (C:UserstomfiCodeDiscordBotnode_moduleswslibevent-target.js:132:16)
at WebSocket.emit (node:events:394:28)
Advertisement
Answer
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,
})