Возвращаемое значение функции равно undefined - discord

    
    if (message.content.startsWith(`${prefix}mus`)) {
        function catchSong(result) {
            console.log(result)
            return result;
        }

        const args = message.content.substring(prefix.length).split(' ');
        let absoluteArgs = args[1] + " " + args[2] + " " + args[3] + " " + args[4] + " " + args[5] + " " + args[6];

        if (!absoluteArgs) {
            message.reply("You don't send a music name")
        }

        if (!args[1]) {
            message.reply("You don't send a music name")
        }

        if (!args[2] === undefined) args[2] = '';
        if (!args[3] === undefined) args[3] = '';
        if (!args[4] === undefined) args[4] = '';
        if (!args[5] === undefined) args[5] = '';
        if (!args[6] === undefined) args[6] = '';

        youtube.searchVideos(absoluteArgs)
            .then(function result(result) {
                let songUrl = result[0].url;
                catchSong(songUrl)
        })
    }
})

функция catchSong() работает таким образом, что берет значение songUrl, для дальнейшей работы с вышеупомянутым songUrl, но когда я пытаюсь вывести значение переменной вне функции songUrl, то получаю undefined, есть ли какие-нибудь способы решения?


Ответы (0 шт):