I ran into the problem that when writing the command / play "link to youtube" the bot does not respond, a couple of minutes ago it was still responding to Now playing and the name of the song, but now nothing here is the code:
import discord
from discord.ext import commands
import yt_dlp
import youtube_dl
from discord import FFmpegPCMAudio
from discord import FFmpegAudio
from discord import FFmpegOpusAudio
intents = discord.Intents.default()
intents.voice_states = True
intents.message_content = True
bot = commands.Bot(command_prefix='/', intents=intents)
@bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}')
@bot.command()
async def join(ctx):
channel = ctx.author.voice.channel
voice_client = ctx.voice_client
if voice_client is not None:
await voice_client.move_to(channel)
else:
await channel.connect()
@bot.command()
async def play(ctx, *, query):
voice_client = ctx.voice_client
if not voice_client.is_playing():
if 'youtube.com' in query:
with yt_dlp.YoutubeDL({}) as ydl:
info = ydl.extract_info(query, download=False)
url = info['formats'][0]['url']
else:
query = f'ytsearch:{query}'
with yt_dlp.YoutubeDL({}) as ydl:
info = ydl.extract_info(query, download=False)
url = info['entries'][0]['formats'][0]['url']
voice_client.play(discord.FFmpegPCMAudio(url))
await ctx.send(f'♫ Сейчас играет: {query}')
else:
await ctx.send('Bot is already playing music')
@bot.command()
async def leave(ctx):
voice_client = ctx.voice_client
if voice_client.is_connected():
await voice_client.disconnect()
await ctx.send('♫ Бот покинул голосовой канал ♫')
else:
await ctx.send('♫ Бот не подключён к голосовому каналу ♫')
bot.run('my bot token') ```