Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

50
Vistas
Getting a TypError saying that my exported function is not a function with nodejs

My goal is to create a discord bot that plays Spotify music, but when I run the function that plays music it gives me the error:

TypeError: playSong is not a function

Here is what is in my 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 };

And here is in my 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)
            }


        }

I have tried to use other methods I know of but it all comes down to the same TypeError. T_T

7 months ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try to replace

const playSong = () => 

with

function playSong()
7 months ago · Juan Pablo Isaza Denunciar

0

Instead of

module.exports = { playSong };

Use

module.exports.playSong = playSong;
7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.