const { createAudioPlayer, createAudioResource } = require('@discordjs/voice');
const { Client } = require('discord.js');
const client = new Client();
client.on('ready', async() => {
const channel = client.channels.cache.get('1085977431808159744');
const connection = await joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
selfDeaf: false,
selfMute: false
});
const player = createAudioPlayer();
const receiver = connection.receiver;
receiver.speaking.on('start', (userId) => {
console.log(`${userId} - started talking`)
if (userId === '633223783204782090') {
const audioStream = receiver.subscribe(userId);
const resource = createAudioResource(audioStream);
player.play(resource);
connection.subscribe(player);
}
});
receiver.speaking.on('end', (userId) => {
console.log(`${userId} - stopped talking`)
if (userId === '633223783204782090') {
player.stop();
}
});
});