gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
code to join tokens in voice discord.js v14
- User
code to join tokens in voice discord.js v14
- Assistant
In Discord.js v14, the
playVoiceChannel()method has been replaced with thejoinVoiceChannel()method. Here's a code snippet that demonstrates how to use thejoinVoiceChannel()method to join a voice channel and play audio:javascriptconst { joinVoiceChannel } = require('@discordjs/voice'); client.on('messageCreate', async (message) => { if (message.content === '!join') { if (!message.member) return; // Ignore messages not from guilds const voiceChannel = message.member.voice.channel; if (!voiceChannel) { return message.reply('You need to be in a voice channel to use this command!'); } // Join the voice channel const connection = joinVoiceChannel({ channelId: voiceChannel.id, guildId: voiceChannel.guild.id, adapterCreator: voiceChannel.guild.voiceAdapterCreator, }); connection.on('stateChange', (state) => { console.log(`Connection transitioned from ${state.oldState.status} to ${state.newState.status}`); }); // Play audio // Add your audio code here message.reply('Joined the voice channel!'); } });