Mi objetivo es crear un bot de discord que reproduzca música de Spotify, pero cuando ejecuto la función que reproduce música me da el error:
TypeError: playSong no es una función
Esto es lo que hay en mi api.js:
const playSong = (songName) => { spotifyApi.searchTracks(songName) .then(data => { const track = data.body.tracks.items[0]; const trackId = track.id; spotifyApi.play({ device_id: '', uris: [`spotify:track:${trackId}`] }); }) .catch(err => { console.error(err); }); }; module.exports = { playSong };
Y aquí está en mi play.js:
const { playSong } = require('../spotify_api/api.js'); let msg = message.content let song = msg.replace('!play ', ''); //creates the audio player if (message.content === `!play ${song}`) { //VoiceChannel IDs //Audio Player const player = createAudioPlayer() player.on(AudioPlayerStatus.Playing, () => { client.message.reply(`Now playing: ${song}`) console.log(`Now playing: ${song}`) }) player.on('error', err => { console.log(`Error: ${err.message} with resource`) }) //creat and play audio player.play(playSong(song)); //This is where I call the function //Subscribe the connection to the audio player const subscription = connection.subscribe(player) if (subscription) { //Unsubscribe the subscription setTimeout(() => subscription.unsubscribe(), 120000) } }
He intentado usar otros métodos que conozco, pero todo se reduce al mismo TypeError. T_T