Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set --default-search "ytsearch" (or run youtube-dl "ytsearch:" ) #22221

Closed
FabricioZZg1 opened this issue Aug 26, 2019 · 1 comment
Closed

Set --default-search "ytsearch" (or run youtube-dl "ytsearch:" ) #22221

FabricioZZg1 opened this issue Aug 26, 2019 · 1 comment
Labels

Comments

@FabricioZZg1
Copy link

@FabricioZZg1 FabricioZZg1 commented Aug 26, 2019

Checklist

  • I'm asking a question
  • I've looked through the README and FAQ for similar questions
  • I've searched the bugtracker for similar questions including closed ones

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()

song_there = os.path.isfile("song.mp3")
try:
    if song_there:
        os.remove("song.mp3")
except PermissionError:
    await ctx.send("""Espera a musica irmao

: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?

@dstftw
Copy link
Collaborator

@dstftw dstftw commented Aug 26, 2019

This is not a discord support forum.

@dstftw dstftw closed this Aug 26, 2019
@ytdl-org ytdl-org locked as off topic and limited conversation to collaborators Aug 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.