import discord, ezcord, os, asyncio, yt_dlp
intents = discord.Intents.all()
intents.voice_states = True
bot = ezcord.Bot(
intents=intents,
debug_guilds=[1232401810845601813]
)
queues = {}
voice_clients = {}
yt_dl_options = {"format": "bestaudio/best"}
ytdl = yt_dlp.YoutubeDL(yt_dl_options)
ffmpeg_options = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5','options': '-vn -filter:a "volume=0.25"'}
@bot.event
async def on_message(message):
if message.content.startswith("?play"):
try:
voice_client = await message.author.voice.channel.connect()
voice_clients[voice_client.guild.id] = voice_client
except Exception as e:
print(e)
try:
url = message.content.split()[1]
loop = asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False))
song = data['url']
player = discord.FFmpegOpusAudio(song, **ffmpeg_options)
voice_clients[message.guild.id].play(player)
except Exception as e:
print(e)