Estoy intentando hacer un bot de música para mi servidor de discordia. Cuando ejecuto el código, el bot se une a mi llamada, sin embargo, detiene instantáneamente el código y ejecuta "Se produjo un error al intentar conectarse".
Dice en la consola:
La única parte del código de donde proviene 'adapterCreator' está aquí:
if (command === 'play'){ if (!args.length) return message.channel.send('Please provide the second argument!'); let song = {}; joinVoiceChannel({ channelId: message.member.voice.channel.id, guildId: message.guild.id, adapterCreator: message.guild.voiceAdapterCreator })El código que define el mensaje:
Todo esto está bajo async execute(message, args, command, client, Discord){} en la carpeta play.js
const voiceChannel = message.member.voice.channel; if (!voiceChannel) return message.channel.send('You must be in a channel to run this command!') const permissions = voiceChannel.permissionsFor(message.client.user); if (!permissions.has('CONNECT')) return message.channel.send('You do not have the permissions to do this!'); if(!permissions.has('SPEAK')) return message.channel.send('You do not have the permissions to do this!'); const server_queue = queue.get(message.guild.id);En el controlador de comandos main.js:
else if (command === 'play'){ client.commands.get('play').execute(message, args, command); }EDIT #2: Mostrar intenciones:
const { Client, Intents, DiscordAPIError, Collection } = require('discord.js'); const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); const prefix = '-' const fs = require('fs'); client.commands = new Collection(); const command = require('./command') const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js')); for(const file of commandFiles){ const command = require(`./commands/${file}`); client.commands.set(command.name, command); }Intenté de la misma manera que lo hiciste en tu código y funcionó bien y no puedo reproducir el bloqueo. Así que el problema podría no ser el código.
¿Has probado a actualizar los paquetes? ( npm update )
Tiene una advertencia de desuso para el evento de mensaje. Esto no solucionará el problema, pero sería bueno cambiarlo a messageCreate .
Además, para reproducir música más tarde, necesitará la conexión cuando el bot se una a un canal de voz. Asigne el resultado de joinVoiceChannel a una variable.