PythonistaGuild / Wavelink

A powerful Lavalink library for Discord.py.
https://wavelink.dev
MIT License
396 stars 183 forks source link

Playing a user's track from a file? #317

Closed shizamuru-dev closed 3 months ago

shizamuru-dev commented 3 months ago

Hi, I was wondering if there is any way to play the sound from a file attached by the user?

I don't see in the documentation mentioning any local source (for uploading a file to the server, and further playback), or the possibility to add a raw track (via discord.File.fb).

EvieePy commented 3 months ago

Hey if you have an attachment and the attachment still exists in the channel (E.g the message has not been deleted) you can use the url of the attachment to search tracks directly.

tracks: wavelink.Search = await wavelink.Playable.search(attachment.url)

# Rest of code...

If you have files on your server that you want to play you can pass, None to source= in the Playable.search()

tracks: wavelink.Search = await wavelink.Playable.search("local.mp3", source=None)

# Rest of code...