#đź”’ Music bot
8 messages · Page 1 of 1 (latest)
@grim flicker
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
So my code is :
`queue = {} # Par serveur (guild.id)
now_playing = {}
Configuration de téléchargement YouTube
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': 'downloads/%(title)s.%(ext)s',
'quiet': True,
'noplaylist': True,
'extractaudio': True,
'audioformat': 'mp3'
}
def get_embed(title, description):
return discord.Embed(
title=title,
description=description,
color=discord.Color.from_str("#90EE90") # vert pâle
)
async def play_next(ctx):
guild_id = ctx.guild.id
if queue.get(guild_id):
song = queue[guild_id].pop(0)
now_playing[guild_id] = song
source = discord.FFmpegPCMAudio(song['path'])
vc = ctx.guild.voice_client
if vc:
embed = get_embed("▶️ Lecture en cours", f"**{song['title']}**")
await ctx.send(embed=embed)
vc.play(source, after=lambda e: asyncio.run_coroutine_threadsafe(play_next(ctx), client.loop))
else:
now_playing[guild_id] = None
await asyncio.sleep(600)
if not queue.get(guild_id) and ctx.guild.voice_client:
await ctx.guild.voice_client.disconnect()
@client.command()
async def play(ctx, *, search: str):
voice = ctx.author.voice
if not voice:
return await ctx.send("❌ Tu dois être dans un salon vocal.")
vc = ctx.guild.voice_client
if not vc or not vc.is_connected():
vc = await voice.channel.connect()
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(f"ytsearch:{search}", download=True)['entries'][0]
filename = ydl.prepare_filename(info)
guild_id = ctx.guild.id
song = {'title': info['title'], 'path': filename}
if guild_id not in queue:
queue[guild_id] = []
queue[guild_id].append(song)`
` if not now_playing.get(guild_id):
await play_next(ctx)
else:
embed = get_embed("🕓 Ajouté à la file", f"{song['title']}")
await ctx.send(embed=embed)
@client.command()
async def queue_cmd(ctx):
if not queue:
embed = discord.Embed(
title="đź“ File d'attente vide",
description="Aucun titre n'est en attente.",
color=discord.Color.from_rgb(144, 238, 144)
)
else:
desc = "\n".join([f"{i+1}. {url}" for i, url in enumerate(queue)])
embed = discord.Embed(
title="📜 File d'attente",
description=desc,
color=discord.Color.from_rgb(144, 238, 144)
)
await ctx.send(embed=embed)
@client.command()
async def stop(ctx):
guild_id = ctx.guild.id
if ctx.voice_client:
ctx.voice_client.stop()
queue[guild_id] = []
now_playing[guild_id] = None
await ctx.voice_client.disconnect()
await ctx.send(embed=get_embed("🛑 Musique arrêtée", "La lecture a été stoppée et la file vidée."))
else:
await ctx.send("❌ Le bot n'est pas connecté.")
@client.command()
async def leave(ctx):
if ctx.voice_client:
await ctx.voice_client.disconnect()
await ctx.send(embed=get_embed("👋 Déconnexion", "Le bot a quitté le salon vocal."))
else:
await ctx.send("❌ Le bot n'est pas dans un salon vocal.")
@client.command()
@commands.has_permissions(administrator=True)
async def skip(ctx):
if ctx.voice_client and ctx.voice_client.is_playing():
ctx.voice_client.stop()
embed = discord.Embed(
title="âŹď¸Ź Titre passĂ©",
description="Le morceau actuel a été ignoré.",
color=discord.Color.from_rgb(144, 238, 144)
)
await ctx.send(embed=embed)
else:
await ctx.send("⚠️ Rien à ignorer pour le moment.")`
the message is in french but dont worry bt it
:warning: The owner of this post is no longer in the server.
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.