Make a Discord Bot with Python (Part 7: Music Bot) | Latest Discord Py Version
Why Stack Overflow recommends it
Stack Overflow users link it when answering or asking about discord.py music bots, FFmpeg setup, and playing YouTube audio in voice channels.
Recommended by 2 people across 2 different months, 2021 to 2022.
What it is
A 21-minute Python tutorial by Alexa Fazio, part 7 of her Discord bot series, showing how to build a music bot with discord.py. The bot joins voice channels and plays YouTube audio using FFmpeg and youtube_dl, with pause, resume, stop and leave commands.
What people said
Recommends Aditya Tomar · 2021-02 · Stack Overflow · on “discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: __init__() missing 1 required positional argument: 'source'”
In your vc.play(discord.FFmpegPCMAudio... line, you're ussing FFmpeg, but you never imported it. import discord from discord.ext import commands import random import json import math import os import ffmpeg @client.command() async def pmartina(ctx): voicechannel = discord.utils.get(ctx.guild.channels, name='Musica') vc = await voicechannel.connect() vc.play(discord.FFmpegPCMAudio(excutable="martina.mp3"), print('done')) Also, make sure to download ffmpeg [LINK] and set up the path correctly. There are many videos online to help you do this correctly, such as this [LINK] one for Windows and this [LINK] one for MacOS. If you want a more detailed walkthrough to make a music bot, refer to this v
Recommends Mindaugas Bernatavičius · 2022-02 · Stack Overflow · on “how to apply audio filter using discord.py/ffmpeg”
The example you listed plays music from youtube (as most discord bots seem to be doing) with the ytdl library. Ytdl is the one that can interact with the ffmpeg to convert video to audio only (as can be seen in this documentation: [LINK] ). This video implements something similar with ffmpeg: [this video] (added the approximate timestamp). So what you will need to do is to pass the filter flags, similarly to the JS example you linked. If you don't want to use Ytdl you will need to interface with ffmpeg directly.
Cites Binu · 2021-01 · Stack Overflow · on “How to make a discord music bot to recognize the end of song or where it is playing”
@kidwhowantstolearnpython Sorry I don't understand what you mean. (English isn't my native language.) If you're asking about the format of code I pasted in question, it is written in python. Or if you are asking about the line 9 parameter “url”, it takes YouTube video's link. Line 18 parameter “name” is the voice channel’s name where you want to bring a bot in. It works like this. Once you send a message “!play [Youtube video URL]” bot will join voice channel, and plays the song. Below link is the original author’s video. Hope this helps. [this video]
Cites Lars · 2021-06 · Stack Overflow · on “Why is my bot not replacing the file if it already exists?”
I'm trying to follow this tutorial [this video] on how to build a music bot for discord. I'm using pycharm 2021.1.1 and anaconda 3 as my interpreter (python 3.7) on win10. I added some changes but none should cause this behavior: The bot tries to download but fails because the file already exists. The file is most likely song.mp3 but it is supposed to be deleted in the line: (I tried both versions, none works, I think it is the same issue) Why is the file song.mp3 not deleted? Have I done any other mistakes that I'm unaware of and would prevent the bot from playing music? if song_there: # os.remove('song.mp3') os.remove(os.path.join(os.getcwd(),"song.mp3")) Minimal code: import discord from disco