0

import discord from discord.ext import commands import os

class music(commands.Cog): def init(self, bot): self.bot = bot print('Модуль {} загружен'.format(self.class.name))

@commands.command()
async def play(self, ctx, *, file_name: str):
    voice_channel = ctx.message.author.voice.channel
    if not voice_channel:
        await ctx.send("Вы не находитесь в голосовом канале!")
        return

    vc = await voice_channel.connect()

    audio_file = f'audio_files/{file_name}.mp3'
    if not os.path.isfile(audio_file):
        await ctx.send( f"Файл {file_name}.mp3 не найден." )
        return

    source = discord.FFmpegPCMAudio(audio_file)
    vc.play(source)

def setup(bot): bot.add_cog(music(bot))

Ignoring exception in command play:
Traceback (most recent call last):
  File "C:\bot_my\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\bot_my\cogs\music.py", line 17, in play
    vc = await voice_channel.connect()
  File "C:\bot_my\venv\lib\site-packages\discord\abc.py", line 1274, in connect
    raise ClientException('Already connected to a voice channel.')
discord.errors.ClientException: Already connected to a voice channel.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\bot_my\venv\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "C:\bot_my\venv\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\bot_my\venv\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: Already connected to a voice channel.

1 ответ 1

1
@commands.command()
async def play(self, ctx, *, file_name: str):
    voice_channel = ctx.message.author.voice.channel
    channel = ctx.message.guild.voice_client
    if not voice_channel:
        await ctx.send("Вы не находитесь в голосовом канале!")
        return

    await voice_channel.connect()

    audio_file = f'audio_files/{file_name}.mp3'
    if not os.path.isfile(audio_file):
        await ctx.send( f"Файл {file_name}.mp3 не найден." )
        return

    source = discord.FFmpegPCMAudio(audio_file)
    channel.play(source)
1
  • не работает Traceback (most recent call last): File "C:\bot_my\venv\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke await ctx.command.invoke(ctx) File "C:\bot_my\venv\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke await injected(*ctx.args, **ctx.kwargs) File "C:\bot_my\venv\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: Already connected to a voice channel. 18 мар в 18:42

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.