Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Set --default-search "ytsearch" (or run youtube-dl "ytsearch:" ) #22221
Comments
|
This is not a discord support forum. |
Checklist
Question
Guys, i have this code to play my discord bot:
=-==-=-=-=-=-=-=-=
@client.command(pass_context=True, brief="This will play a song 'play [url]'", aliases=['play'])
async def tocaaquela(ctx, url: str):
channel = ctx.message.author.voice.channel
if not channel:
await ctx.send("Tu nao estas em um canal")
return
voice = get(client.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
:regional_indicator_b: :regional_indicator_e: :regional_indicator_c: :regional_indicator_k: :regional_indicator_e: :regional_indicator_r: :regional_indicator_t: :regional_indicator_o: :regional_indicator_x: :regional_indicator_i: :regional_indicator_n: :regional_indicator_a:""")
return
await ctx.send("Preparando pra dar aquela palinha...")
print("Someone wants to play music let me get that ready for them...")
voice = get(client.voice_clients, guild=ctx.guild)
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
for file in os.listdir("./"):
if file.endswith(".mp3"):
os.rename(file, 'song.mp3')
voice.play(discord.FFmpegPCMAudio("song.mp3"))
voice.volume = 100
voice.is_playing()
await ctx.send("Só segura e ouve")
-=-===-=-=-=-=-=-=-=-=-
But with this code, the bot just reads the song if there's a URL. My question is: How can I make to just type the song and the bot starts to play it?