YouTube DL is not the best for a Music Disocrd bot. I recommend using Wavelink. You can create your own commands (in or not in a Cog) or you can use dismusic
The below example if for using wavelink with a pre-made music cog named dismusic
# 1 - Install ffmpeg (and add to path)
# Debian/Ubuntu -
# apt install ffmpeg -y - On Ubuntu
# Windows -
# Download ffmpeg, add to PATH or copy the ffmpeg.exe to System32 Folder
# 2 - Install discord, wavelink, lavalink, PyNacl and dismusic with the command below
# Debian/Ubuntu -
# pip3 install lavalink wavelink discord PyNacl dismusic
# Windows -
# pip install lavalink wavelink discord PyNacl dismusic
# Code for a basic discord bot
from discord.ext import commands
client = commands.Bot(command_prefix='--')
@client.event
async def on_ready():
print('+ Logged in as {0.user}'.format(bot))
# Lavalink node to connect to
client.lava_nodes = [
{
# a free public node
# ----------------------
# 'host': "lava.link",
# 'port': 80,
# 'rest_uri': f'http://lava.link:80',
# 'password': 'anyPassword',
# for hosting your own Lavalink locally (More stable)
# Follow the steps below this code snippet only if you are doing this
#
# ----------------------
'host': "127.0.0.1",
'port': 2333,
'rest_uri': f'http://127.0.0.1:2333',
'password': 'youshallnotpass',
# Other Settings
# ----------------------
'identifier': 'MAIN',
'region': 'singapore'
}
]
# loading the installed, pre-made music cog to the bot
client.load_extension('dismusic')
# Running the bot
bot.run("DoNotShareYourTOKEN")
If you chose to select the free public lava.link server (http://lava.link:80), you can skip steps below
You can run the commands below, line by line, to start your own Lavalink server if you use Debain/Ubuntu
sudo apt install wget curl default-jdk -y
mkdir Lavalink && cd Lavalink # Optional
wget "https://github.com/freyacodes/Lavalink/releases/download/3.4/Lavalink.jar"
curl "https://raw.githubusercontent.com/hirusha-adi/Near/main/others/application.yml" >> "application.yml"
java -jar ./Lavalink.jar
If you are using windows to host the discord (which is not the best idea, but still, if you want to), follow the steps written bel
- Install java and add to PATH
- Download Lavalink.jar and application.yml
- Put both downloaded files to a same folder
- Open CMD or Powershell in that folder and run
java -jar Lavalink.jar
Available Commands -
--play - Play a song or playlist
--pause - Pause player
--connect - Connect to vc
--seek - Seek player
--nowplaying - Now playing
--queue - See queue
--equalizer - Set equalizer
--volume - Set volume
--resume - Resume player
--loop - Loop song/playlist