Я пытаюсь создать команду для моего бота Discord, которая будет воспроизводить музыку. Однако пишет, что не подключен ни к одному голосовому каналу.
Сообщение об ошибке:
[2025-12-28 15:10:21,086] {_init_.py:173} ERROR - Code error in command play...
Traceback (most recent call last):
File "C:\Users\rain\.virtualenvs\TWM-LveKoQPz\Lib\site-packages\discord\ext\commands\core.py", line 235, in wrapped
ret = await coro(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\rain\Documents\TWM\TWM\cogs\voice.py", line 146, in play
voice.play(source)
File "C:\Users\rain\.virtualenvs\TWM-LveKoQPz\Lib\site-packages\discord\voice_client.py", line 605, in play
raise ClientException('Not connected to voice.')
discord.errors.ClientException: Not connected to voice.
Вот часть кода. Есть еще кое-что, но я не включил это.
@commands.command()
async def play(self, ctx, *, arg):
"""
Checks where the command's author is, searches for the requested music,
joins the same channel as the command's author, and then plays the audio
directly from YouTube.
:param ctx: discord.ext.commands.Context
:param arg: str
arg can be a YouTube URL or a normal search query.
:return: None
"""
try:
voice_channel = ctx.author.voice.channel
# If the command's author is not connected, return.
except AttributeError as e:
print(e)
await ctx.send("Please connect to the voice channel first!")
return
# Finds the author's session.
session = ctx.guild.voice_client
# Searches for the video.
with yt_dlp.YoutubeDL({'format': 'bestaudio', 'noplaylist': 'True'}) as ydl:
try:
requests.get(arg)
except Exception as e:
print(e)
info = ydl.extract_info(
f"ytsearch:{arg}", download=False
)['entries'][0]
else:
info = ydl.extract_info(arg, download=False)
url = info['formats'][0]['url']
thumb = info['thumbnails'][0]['url']
title = info['title']
# Finds an available voice client for the bot.
voice = ctx.guild.voice_client
if not voice:
await voice_channel.connect()
voice = ctx.guild.voice_client
await ctx.send(thumb)
await ctx.send(f"Playing {title}")
source = await discord.FFmpegOpusAudio.from_probe(
url, **FFMPEG_OPTIONS
)
voice.play(source)
Подробнее здесь: https://stackoverflow.com/questions/798 ... ce-channel
Discord.errors.ClientException: не подключен к голосу в голосовом канале ⇐ Python
Программы на Python
1766971696
Anonymous
Я пытаюсь создать команду для моего бота Discord, которая будет воспроизводить музыку. Однако пишет, что не подключен ни к одному голосовому каналу.
Сообщение об ошибке:
[2025-12-28 15:10:21,086] {_init_.py:173} ERROR - Code error in command play...
Traceback (most recent call last):
File "C:\Users\rain\.virtualenvs\TWM-LveKoQPz\Lib\site-packages\discord\ext\commands\core.py", line 235, in wrapped
ret = await coro(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\rain\Documents\TWM\TWM\cogs\voice.py", line 146, in play
voice.play(source)
File "C:\Users\rain\.virtualenvs\TWM-LveKoQPz\Lib\site-packages\discord\voice_client.py", line 605, in play
raise ClientException('Not connected to voice.')
discord.errors.ClientException: Not connected to voice.
Вот часть кода. Есть еще кое-что, но я не включил это.
@commands.command()
async def play(self, ctx, *, arg):
"""
Checks where the command's author is, searches for the requested music,
joins the same channel as the command's author, and then plays the audio
directly from YouTube.
:param ctx: discord.ext.commands.Context
:param arg: str
arg can be a YouTube URL or a normal search query.
:return: None
"""
try:
voice_channel = ctx.author.voice.channel
# If the command's author is not connected, return.
except AttributeError as e:
print(e)
await ctx.send("Please connect to the voice channel first!")
return
# Finds the author's session.
session = ctx.guild.voice_client
# Searches for the video.
with yt_dlp.YoutubeDL({'format': 'bestaudio', 'noplaylist': 'True'}) as ydl:
try:
requests.get(arg)
except Exception as e:
print(e)
info = ydl.extract_info(
f"ytsearch:{arg}", download=False
)['entries'][0]
else:
info = ydl.extract_info(arg, download=False)
url = info['formats'][0]['url']
thumb = info['thumbnails'][0]['url']
title = info['title']
# Finds an available voice client for the bot.
voice = ctx.guild.voice_client
if not voice:
await voice_channel.connect()
voice = ctx.guild.voice_client
await ctx.send(thumb)
await ctx.send(f"Playing {title}")
source = await discord.FFmpegOpusAudio.from_probe(
url, **FFMPEG_OPTIONS
)
voice.play(source)
Подробнее здесь: [url]https://stackoverflow.com/questions/79856390/discord-errors-clientexception-not-connected-to-voice-when-in-a-voice-channel[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия