client.on('messageCreate', async (message) => {
if (message.author.bot) return;
if (message.content.toLowerCase() === '!join') {
// Check if the author is in a voice channel
if (!message.member.voice.channel) {
message.reply('You need to be in a voice channel to use this command!');
return;
}
// Join the user's voice channel
const channel = message.member.voice.channel;
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
message.reply(`Joined ${channel.name}`);
// You can add additional functionality here, such as playing music, etc.
// For now, let's just log when the bot leaves the channel.
connection.on('stateChange', (state) => {
console.log(`Connection state change: ${state.status}`);
if (state.status === 'Disconnected') {
console.log('Left the channel');
}
});
}
});
client.on('messageCreate', async (message) => {
if (message.author.bot) return;
if (message.content.toLowerCase() === '!join') {
// Check if the author is in a voice channel
if (!message.member.voice.channel) {
message.reply('You need to be in a voice channel to use this command!');
return;
}
// Join the user's voice channel
const channel = message.member.voice.channel;
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});
message.reply(`Joined ${channel.name}`);
// You can add additional functionality here, such as playing music, etc.
// For now, let's just log when the bot leaves the channel.
connection.on('stateChange', (state) => {
console.log(`Connection state change: ${state.status}`);
if (state.status === 'Disconnected') {
console.log('Left the channel');
}
});
}
});