python discord music bot

Solutions on MaxInterview for python discord music bot by the best coders in the world

showing results for - "python discord music bot"
Leo
02 Jan 2018
1There were some changes to youtube_dl and FFmpeg, so this should work.
2
3import discord
4
5import youtube_dl
6
7from discord.ext import commands
8
9ydl_opts = {
10    'format': 'bestaudio/best',
11    'postprocessors': [{
12        'key': 'FFmpegExtractAudio',
13        'preferredcodec': 'mp3',
14        'preferredquality': '192',
15    }],
16}   
17
18def endSong(guild, path):
19    os.remove(path)                                   
20
21@cat.command(pass_context=True)
22async def play(ctx, url):
23    if not ctx.message.author.voice:
24        await ctx.send('you are not connected to a voice channel')
25        return
26
27    else:
28        channel = ctx.message.author.voice.channel
29
30    voice_client = await channel.connect()
31
32    guild = ctx.message.guild
33
34    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
35        file = ydl.extract_info(url, download=True)
36        path = str(file['title']) + "-" + str(file['id'] + ".mp3")
37
38    voice_client.play(discord.FFmpegPCMAudio(path), after=lambda x: endSong(guild, path))
39    voice_client.source = discord.PCMVolumeTransformer(voice_client.source, 1)
40
41    await ctx.send(f'**Music: **{url}')
42Optional, useful function
43If you want you can make your bot leave the voice channel after the song/music stop playing. Add this at the end of your code.
44
45while voice_client.is_playing():
46        await asyncio.sleep(1)
47    else:
48        await voice_client.disconnect()
49        print("Disconnected")
50If something wouldn't work
51If you had any problem with understanding the code or something wouldn't work, comment under my answer and I'll try my best to help you. Btw if you are thinking about hosting your bot on Heroku I can help you with that, because there are some things you need to do to make your music bot run there.
queries leading to this page
discord music bot python tutorialdiscord music bot source code pythonmusic bot discord pydiscord music bot commands discord pysimple music bot discord pyhow to play a music in discord bot pythonhow to code discord music bot pythonhow to make a python music botdiscord music python how does a music bot work pythonvote system for bot discord python music bothow to make a discord music bot python codegithub discord py music botdiscord music bot discord pymusic bot in discordhow to code a discord music bot pythonhow to make music bot discord pythonhow to play music using bot using discord pycreate que music bot discord pythondiscord python musicmusic bot made with python discorddiscord py spotify music botdiscord py music bot examplemusic bot discord pyyt music discord bot pythondiscord py how to download music for bothow to make a music discord py bothow to code a music bot for discord pythonpython discord music bot codemake basic music bot discord pydiscord bot music pythonbot discord python musiccode for python discord bot to play musicmake a music discord bot with pythonpython discord music bot send message when donediscord py how to make a music botplay music in discord bot pythonmusic bots discord in pythonhow to code discord music bot discord pymusic bot pythondiscord music bot code python discord bot music example pyhow to make a discord bot play music using pythondiscord python music bot codehow to make a discord music bot from pyhonmusic bot discord py disconcreate a music bot discord pypython discord bot play musichow to make a discord music bot in pythonmusicbot discord pyhow to get the bot to play music in discord pyspotipy discord music bot pythonplaying music with discord bot using pythondiscord py musicbasic python discord music bothow to play music with discord python botdiscord music bot open source pythonpython music discord botmake a legal music bot discord pythonhow to play music on discord bot pythonpython music bot discordhow to make discord bot for music pythonmusic bot discord py codepyhton music player discord botdiscord bot play music pythondiscord py music bot codesource code bot music discord pyhow to make a discord py bot musicdiscord py make music botspotify discord music bot pythondiscord bot python music botsimple discord music bot pythonbot music pythonmusic bot with discord pybot music discord pydiscord music bot pymusic bot python discord pymusic bot python discordhow to make music bot discord pymusic discord bot python codediscord music bot python source codediscord python musicbotpython music botdiscord bot python music codepython discord bot music source codemusic discord bot py sourcepython discord music bot spotifyhow to get the discord bot to play music pythonpython discord music bot githubhow to make a music bot discord pyhow to make music discord bot with discord pydiscord music bot pymusic discord bot pythondiscord bot python musicdiscord music bot pytondiscord music bot github pythondiscord py simple music bot codediscord py music botmusic bot with pythonbot music discord py discord py bot playing music with pythonhow to add music to discord pythonmake a discord bot with python musichaw to make a music discord bot in pythonmusic bot discord pythonhow to create a music bot using discord pypython simple discord music botmake discord bot play music pythonmusic player discord bot code in pythonexample music bot dsicord pypython discord play musicmusic bot discord how to make in pythondisocrd music bot python simple discord py music bothow to add music in discord python botdiscord music botpythonhow to make music bot in discord pydiscord music bot pythonnworking music bot source code discord pydiscord music bot code discord pypython py how to disconect a music botbuild discord music bot pythondiscord python youtube music botdiscord python music boteasy to make python discord music botpython discord bot musicbot discord music pythonmusic bots for discord pythonhow to create a music bot pythondiscord python bot with musicdiscord py bot musichow to make a music bot on discord pythonmake discord music bot pythonsimple music bot pythonpython discord music bot loopcreate discord music bot pythonmake a music bot discord pythoncreate a discord music bot pythonhow to make a music bot in discord pymake your own discord bot 7c music bot pythonmusic bot in pythonmusic discord pythonmusic bot discord py githubdiscord music bot python codepython bot musicdiscod music bot python codediscord py how to play music though the bothow to make python music bot discordhow to make discord music bot pythondiscord py music bot codepy discord music botdiscord music bot in pythonlisten music discord bot pythonhow to make discord spotify music bot pythondiscord bot python play musichow to make discord music bot in pythonhow to make a music bot discord py 2021musicbot discord py on pythonpython how to get discord bot to play musicdiscord music bot script pythonlibraries needed to make a discord music bot with pythonadd basic music bot discord pyhow to make a music bot discord python tutorialhow to make a discord music bot with pythondiscord python play musicmusic bot code discord pyhow to create a music bot for discord pythonmusic bot discord spotify pythonhow to make a music bot on discord pyhow to make a discord music bot python spotifymusic player discord bot pythonpython music bot discord githubhow to plsy music in discord bot python codemusic bot script discord pydiscord py music botpython discord music bot send something when done playinginstall for music bot discord pythonpython discord music botcreate music bot discord pythonhow to code a discord music bot in pythonhow to create a music bot discord pypython music bot for discordhow to make a youtube music discord bot in pythonhow to make a music bot discord pythonbot discord play music pythonhow to make a discord music bot pythonmusic bot discord source code pythondiscord python how to make music bothow to make discord bot play music pythoncreat bot music for discord pythonmaking a music bot in discord pymake discord py bot with musicdiscord py music bot tutorialmusic bot discord python rhytmhow to bot for make open music discord pymake discord py music botdiscord music bot example pythondiscord python music bot open sourceplay music discord bot pythondiscord bot python voice channel musichow to make bot play music discord pythonhow to make a music bot in discord pythoncreate a simple music bot discord pythondiscord music bot with pythonhow to ake discord music bot in pythonpremium discord music bot pythonmusic bot discord code pythondiscord play music bot pypython programming discord music bothow to create a music bot on discord pythonplaying music in discord bot pythondiscord py music botmusic bot python discord pihow to create music bot in pythonmusic bot discord python githubhow to make a discord bot play music pythondiscord music bot program pythondiscord bot in python musichow to get my discord bot to play music discord pyhow to make a discord 22music 22 bot pythonpython discord music bot do when donecreate discord bot that plays music pythonhow to make a music discord bot pythondiscord music bot pythonpython discord music bot