Search code examples
javascriptdirectorydiscord.js

How to open a file in folders with discord.js


I am now coding a Discord bot in a folder named "bot", and I am making it play audio file. But I face a problem. If every files I want to make it play are stored in "bot", the folder will look mess. So I want to create a new folder named "music" in "bot". But I don't know to open the file in this way. Here is a part of my original code:

if (cmd === "play" && message.member.voice.channel) {
        const connection = await message.member.voice.channel.join();
        const dispatcher = connection.play('01. Snow halation.flac');
        dispatcher.on('start', () => {
            console.log('Now playing!');
        });
        dispatcher.on('finish', () => {
            console.log('Finished playing!');
            connection.disconnect();
        });
        dispatcher.on('error', console.error);

I want let file "01. Snow halation.flac" be in "music", and how can I make it play?


Solution

  • const dispatcher = connection.play('./music/01. Snow halation.flac');