@Vasiliy009

Что делать команды не работают в ffmpeg discord.py?

Сделал бота музыки в дискорде, ни одна команда не работает

music.py
import discord
from discord.ext import commands
import os 

from help_cog import help_cog
from music_cog import music_cog

bot = commands.Bot(command_prefix="/")

bot.remove_command("help")
bot.add_cog(help_cog(bot))
bot.add_cog(music_cog(bot))

bot.run("Token")


music_cog.py
import discord
from discord.ext import commands

from youtube_dl import YoutubeDL

class music_cog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

        self.is_playing = False
        self.is_paused = False

        self.music_queue = []
        self.YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'True'}
        self.FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn', 'executable': 'C:/ffmpeg/bin'}

        self.vc = None

    def search_yt(self, item):
        with YoutubeDL(self.YDL_OPTIONS) as ydl:
            try:
                info = ydl.extract_info("ytsearch:%s" % item, download=False)['entries'][0]
            except Exception:
                return False
        return {'source': info['formats'][0]['url'], 'title': info['title']}

    def play_next(self, ctx):
        if len(self.music_queue) > 0:
            self.is_playing = True

            m_url = self.music_queue[0][0]['source']

            self.music_queue.pop(0)
            self.vc.play(discord.FFmpegPCMAudio(m_url, **self.FFMPEG_OPTIONS), after=lambda e: self.play_next(ctx))
        else:
            self.is_playing = False

    async def play_music(self, ctx):
        if len(self.music_queue) > 0:
            self.is_playing = True
            m_url = self.music_queue[0][0]['source']

            if self.vc is None or not self.vc.is_connected():
                self.vc = await self.music_queue[0][1].connect()

                if self.vc is None:
                    await ctx.send("Нужно, чтобы вы были в голосовом канале")
                    return
            else:
                await self.vc.move_to(self.music_queue[0][1])
            self.music_queue.pop(0)

            self.vc.play(discord.FFmpegPCMAudio(m_url, **self.FFMPEG_OPTIONS), after=lambda e: self.play_next(ctx))
        else:
            self.is_playing = False

    @commands.command(name="play", aliases=["p", "playing"], help="Запустит музыку с ютуба")
    async def play(self, ctx, *args):
        query = " ".join(args)
        voice_channel = ctx.author.voice.channel
        if voice_channel is None:
            await ctx.send("Подключился к голосовому каналу")
        elif self.is_paused:
            self.vc.resume()
        else:
            song = self.search_yt(query)
            if type(song) == type(True):
                await ctx.send("Не могу найти музыку, дайте мне ключевые слова")
            else:
                await ctx.send("Музыка добавлена в очередь")
                self.music_queue.append([song, voice_channel])
                if not self.is_playing:
                    await self.play_music(ctx)

    @commands.command(name="pause", help="Поставить на паузу музыку")
    async def pause(self, ctx, *args):
        if self.is_playing:
            self.is_playing = False
            self.is_paused = True
            self.vc.pause()
        elif self.is_paused:
            self.is_playing = True
            self.is_paused = False
            self.vc.resume()

    @commands.command(name="resume", aliases=["r"], help="Убрать с паузы")
    async def resume(self, ctx, *args):
        if self.is_paused:
            self.is_playing = True
            self.is_paused = False
            self.vc.resume()

    @commands.command(name="skip", aliases=["s"], help="Пропустить музыку")
    async def skip(self, ctx, *args):
        if self.vc is not None and self.vc.is_playing():
            self.vc.stop()
            await self.play_music(ctx)

    @commands.command(name="queue", aliases=["q"], help="Показать все музыки из очереди")
    async def queue(self, ctx):
        retval = ""
        for i in range(min(5, len(self.music_queue))):
            retval += f"{i+1}. {self.music_queue[i][0]['title']}\n"

        if retval != "":
            await ctx.send(retval)
        else:
            await ctx.send("Нет музыки в очереди")

    @commands.command(name="clear", aliases=["c", "bin"], help="Очистить все музыки из очереди")
    async def clear(self, ctx, *args):
        if self.vc is not None and self.is_playing:
            self.vc.stop()
        self.music_queue = []
        await ctx.send("Музыка была удалена из очереди")

    @commands.command(name="leave", aliases=["disconnect", "1", "d"], help="Отключить бота из канала")
    async def leave(self, ctx):
        self.is_playing = False
        self.is_paused = False
        if self.vc is not None and self.vc.is_connected():
            await self.vc.disconnect()
            await ctx.send("Бот покинул голосовой канал")


help_cog.py
import discord 
import asyncio
from discord.ext import commands

class help_cog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot 

        self.help_message = """ ```
.help - Показывает список доступных команд
.p - Найти музыки и запустить
.q - Показать все музыки из очереди
.skip - Пропустить музыку
.clear - Очистить музыки из очереди
.leave - Выгнать бота из голосового канала
.pause - Поставить на паузу музыку
.resume - Снять с паузы музыку
```        
"""
        self.text_channel_text = []
    
    @commands.Cog.listener()
    async def on_ready(self):
        for guild in self.bot.guilds:
            for channel in guild.   text_channels: 
                self.text_channel_text.append(channel)
        await self.send_to_all(self.help_message)

    async def send_to_all(self, msg):
        for text_channel in self.text_channel_text: 
            await text_channel.send(msg)

    @commands.command(name="help", help="Показывает список команд")
    async def help(self, ctx):
        await ctx.send(self.help_message)


Какая ошибка не допускает команды?
  • Вопрос задан
  • 59 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы