Форум сайта python.su
Всем привет.
Данный бот по команде ?play (ссылка) запускает музыку, но следующую ссылку не запускает и
приходится дисконектить его и только тогда он начинает запускать снова музыку.
Ошибку прикрепил ниже
Прошу наведите в чем ошибка и как её решить?
import discord from discord.ext import commands import music cogs = [music] client = commands.Bot(command_prefix='?', intents = discord.Intents.all()) @client.command() async def join1(ctx): await ctx.message.author.voice.channel.connect(reconnect=True) for i in range(len(cogs)): cogs[i].setup(client) client.run("token")
import discord from discord.ext import commands from discord.voice_client import VoiceClient import youtube_dl class music(commands.Cog): def __init__(self, client): self.ydl_opts = {'format': 'bestaudio'} self.FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'} self.client = client @commands.command() async def join(self, ctx): if ctx.author.voice is None: await ctx.send('Ты не в голосовом канале!') else: await ctx.message.author.voice.channel.connect(reconnect=True) @commands.command() async def disconnect(self, ctx): if (ctx.guild.voice_client): # If the bot is in a voice channel await ctx.guild.voice_client.disconnect() # Leave the channel await ctx.channel.send('Вышел') else: # But if it isn't await ctx.send("Я не нахожусь в голосовом канале! 😡") @commands.command() async def pause(self, ctx): await ctx.guild.voice_client.pause() await ctx.send('Пауза') @commands.command() async def resume(self, ctx): await ctx.guild.voice_client.resume() await ctx.send('Снять с паузы') @commands.command() async def play(self, ctx, url): channel = ctx.message.author.voice.channel voice = await channel.connect() with youtube_dl.YoutubeDL(self.ydl_opts) as ydl: source = ydl.extract_info(url, download=False)['formats'][0]['url'] voice.play(discord.FFmpegPCMAudio(source, **self.FFMPEG_OPTIONS, executable="D:\\fail\\ff0808\\bin\\ffmpeg.exe")) voice.is_playing def setup(client): client.add_cog(music(client))
Отредактировано i4etverg_ex (Авг. 11, 2021 16:04:54)
Прикреплённый файлы: error.png (72,8 KБ)
Офлайн
Это то же самое, что я ищу о python на онлайн-radio en direct и на других форумах ИТ.
Отредактировано Bernard21 (Сен. 1, 2021 04:51:42)
Офлайн