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 User•2y ago
Message Not Public
Sign In & Join Server To View
pat
pat•2y ago
did you try it?
wen
wenOP•2y ago
yeah it joins but doesnt play anything i also logged generateDependencyReport()
wen
wenOP•2y ago
wen
wenOP•2y ago
@patr.
Deimoss
Deimoss•2y ago
try using path.join instead of resolve path.join(__dirname, "pathFromProjectRoot")
wen
wenOP•2y ago
so
path.join(__dirname, "../../myfile.mp3")
path.join(__dirname, "../../myfile.mp3")
Deimoss
Deimoss•2y 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
wenOP•2y ago
like that ? no like i have all my cmds in one folder and the audio files in another
Deimoss
Deimoss•2y 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
wenOP•2y ago
so it cant be in any folder ? path.join(__dirname, "Audio/sub/file.mp3") and Audio folder is in root dir ?
Deimoss
Deimoss•2y ago
it can be anywhere, just the path has to correct
wen
wenOP•2y ago
alright
Deimoss
Deimoss•2y ago
yeah, looks about right, although i dont know your folder structure so i can't say for sure
wen
wenOP•2y ago
wen
wenOP•2y ago
it just leaves after 3 secs without playing anything
Deimoss
Deimoss•2y ago
so it's idle hmm
wen
wenOP•2y ago
yeah ig
Deimoss
Deimoss•2y ago
eh i haven't worked with voice in a while, lemme check my music bot's code 😄
wen
wenOP•2y ago
sure sure take your time
Deimoss
Deimoss•2y ago
alright, so your code looks fine, so the only thing i can think of is your path to the mp3
wen
wenOP•2y ago
i can show u my folder structure
Deimoss
Deimoss•2y ago
could you maybe show how the code for the audio resource yeah also folder structure
wen
wenOP•2y ago
wen
wenOP•2y ago
Deimoss
Deimoss•2y ago
ah spaces in folder names 🥹 my worst nightmare xd alright, so try using one / slash instead of \
wen
wenOP•2y ago
so /\ ??
Deimoss
Deimoss•2y ago
no just / Audio/Darling...
wen
wenOP•2y ago
ah right les try still nothing
Deimoss
Deimoss•2y ago
alright log the audio resource, maybe it tells us something
wen
wenOP•2y ago
is it because the file is large
Deimoss
Deimoss•2y ago
i doubt it
wen
wenOP•2y ago
wen
wenOP•2y ago
thats the log
Deimoss
Deimoss•2y ago
well... i got no clue, sorry sadge try playing it without inlineVolume
wen
wenOP•2y ago
alright
Deimoss
Deimoss•2y 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
wenOP•2y ago
man this sucks... nothing is working
Deimoss
Deimoss•2y ago
but anyway, good luck dogeHaHa
wen
wenOP•2y ago
thanks man
Deimoss
Deimoss•2y ago
maybe try just taking the examples out of the guide and slowly working your way up just a whole lot of experimentation
wen
wenOP•2y ago
all of this is from the guide 💀
Deimoss
Deimoss•2y ago
can you show your package.json? just interested
wen
wenOP•2y ago
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
yeah its fine @deimoss
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y ago
still the same @qubiet
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
wen
wenOP•2y 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 User•2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server