const Discord = require("discord.js"); require('dotenv').config(); const { joinVoiceChannel, createAudioPlayer, createAudioResource, AudioPlayerStatus } = require('@discordjs/voice'); const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"], partials: ["CHANNEL"] }); const player = createAudioPlayer(); var channelsToMonitor = ['902193996355485778']; function joinChannel(channel) { const connection = joinVoiceChannel({ channelId: channel.id, guildId: channel.guild.id, adapterCreator: channel.guild.voiceAdapterCreator, }); return connection; } function playAudio(connection) { // Subscribe the connection to the audio player (will play audio on the voice connection) const resource = createAudioResource('./music/', 'alarm.mp3'); resource.volume = 1; player.play(resource); connection.subscribe(player); player.on(AudioPlayerStatus.Playing, () => { console.log('ALRM'); }); } client.on('ready', () => { console.log('ready'); }) client.on('messageCreate', async msg => { try { if (channelsToMonitor.indexOf(msg.channel.id) !== -1) { if (msg.content == 'GOGOGO') { const guild = client.guilds.cache.get("857332849119723520"); const channel = guild.channels.cache.get("921415774676058152"); if (!channel) return console.error("The channel does not exist!"); var connection = joinChannel(channel); await playAudio(connection); } } else { if (msg.author.bot) return; } } catch (err) { console.error(err.message); } }); client.login(process.env.DISCORD_TOKEN_2);He configurado esto desde los documentos
¡Y no puedo encontrar por qué no sale ningún audio! El bot se une al canal y dice que se está reproduciendo cuando uso console.log(player) pero, por alguna razón, está ensordecido y no reproduce ningún sonido.
Los bots ahora se unen con sordos propios de forma predeterminada. Proporcione el campo selfDeaf para detener esto:
const connection = joinVoiceChannel({ channelId: channel.id, guildId: channel.guild.id, adapterCreator: channel.guild.voiceAdapterCreator, selfDeaf: false, selfMute: false // this may also be needed })