Дополнен 7 месяцев назад
Если можете, то просто помогите с кодом, буду рад:)
import discord
from discord.ext import commands
import youtube_dl
intents = disnake.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'Бот {bot.user.name} готов к работе!')
@bot.command()
async def join(ctx):
channel = ctx.author.voice.channel
await channel.connect()
@bot.command()
async def leave(ctx):
await ctx.voice_client.disconnect()
@bot.command()
async def play(ctx, url):
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
url2 = info['formats'][0]['url']
voice_client = ctx.voice_client
FFMPEG_OPTIONS = {
'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
'options': '-vn',
}
voice_client.stop()
voice_client.play(discord.FFmpegPCMAudio(url2, **FFMPEG_OPTIONS))
@bot.command()
async def pause(ctx):
ctx.voice_client.pause()
@bot.command()
async def resume(ctx):
ctx.voice_client.resume()