Play local file

is this enough to play an mp3 file ?
let connection;
connection = await joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guild.id,
selfMute: false,
selfDeaf: true,
adapterCreator: message.guild.voiceAdapterCreator,
});

let src = await createAudioResource(
path.resolve(
"../../../pathToFile.mp3"
),

{ inlineVolume: true }
);
src.volume.setVolume(1);

const player = await createAudioPlayer();
await connection.subscribe(player);
await player.play(src);

message.channel.send("playing");
let connection;
connection = await joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guild.id,
selfMute: false,
selfDeaf: true,
adapterCreator: message.guild.voiceAdapterCreator,
});

let src = await createAudioResource(
path.resolve(
"../../../pathToFile.mp3"
),

{ inlineVolume: true }
);
src.volume.setVolume(1);

const player = await createAudioPlayer();
await connection.subscribe(player);
await player.play(src);

message.channel.send("playing");
51 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
pat
pat2y ago
did you try it?
wen
wenOP2y ago
yeah it joins but doesnt play anything i also logged generateDependencyReport()
wen
wenOP2y ago
wen
wenOP2y ago
@patr.
Deimoss
Deimoss2y ago
try using path.join instead of resolve path.join(__dirname, "pathFromProjectRoot")
wen
wenOP2y ago
so
path.join(__dirname, "../../myfile.mp3")
path.join(__dirname, "../../myfile.mp3")
Deimoss
Deimoss2y ago
i mean i don't know if that is the issue, but i've always used path.join and so does the guide, so it's worth a shot is the file outside your project folder?
wen
wenOP2y ago
like that ? no like i have all my cmds in one folder and the audio files in another
Deimoss
Deimoss2y ago
okay, so the second parameter of join isnt the relative path of the file that you are running that code from it's the path from the root of your project (the same place where package.json is located)
wen
wenOP2y ago
so it cant be in any folder ? path.join(__dirname, "Audio/sub/file.mp3") and Audio folder is in root dir ?
Deimoss
Deimoss2y ago
it can be anywhere, just the path has to correct
wen
wenOP2y ago
alright
Deimoss
Deimoss2y ago
yeah, looks about right, although i dont know your folder structure so i can't say for sure
wen
wenOP2y ago
wen
wenOP2y ago
it just leaves after 3 secs without playing anything
Deimoss
Deimoss2y ago
so it's idle hmm
wen
wenOP2y ago
yeah ig
Deimoss
Deimoss2y ago
eh i haven't worked with voice in a while, lemme check my music bot's code 😄
wen
wenOP2y ago
sure sure take your time
Deimoss
Deimoss2y ago
alright, so your code looks fine, so the only thing i can think of is your path to the mp3
wen
wenOP2y ago
i can show u my folder structure
Deimoss
Deimoss2y ago
could you maybe show how the code for the audio resource yeah also folder structure
wen
wenOP2y ago
wen
wenOP2y ago
Deimoss
Deimoss2y ago
ah spaces in folder names 🥹 my worst nightmare xd alright, so try using one / slash instead of \
wen
wenOP2y ago
so /\ ??
Deimoss
Deimoss2y ago
no just / Audio/Darling...
wen
wenOP2y ago
ah right les try still nothing
Deimoss
Deimoss2y ago
alright log the audio resource, maybe it tells us something
wen
wenOP2y ago
is it because the file is large
Deimoss
Deimoss2y ago
i doubt it
wen
wenOP2y ago
wen
wenOP2y ago
thats the log
Deimoss
Deimoss2y ago
well... i got no clue, sorry sadge try playing it without inlineVolume
wen
wenOP2y ago
alright
Deimoss
Deimoss2y ago
honestly, that's my only advice, when i had problems with my music bot the first time i was just throwing shit at the wall and seeing what fixed the problem there's so many things that could cause problems, and you don't even know which one it is until it magically starts working i tried updating some dependencies for my music bot a few weeks ago and everything broke, that's why i hate working with voice
wen
wenOP2y ago
man this sucks... nothing is working
Deimoss
Deimoss2y ago
but anyway, good luck dogeHaHa
wen
wenOP2y ago
thanks man
Deimoss
Deimoss2y ago
maybe try just taking the examples out of the guide and slowly working your way up just a whole lot of experimentation
wen
wenOP2y ago
all of this is from the guide 💀
Deimoss
Deimoss2y ago
can you show your package.json? just interested
wen
wenOP2y ago
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP2y ago
yeah its fine @deimoss
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP2y ago
still the same @qubiet
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP2y ago
i did do that... no logs i'll do that for some reason removing spaces fixed it 💀 ty all ok one more thing im playing local files how do i improve the quality of the output i converted mp3 and flac to opus but its still not that great
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?