불.ext.명령입니다.오류가 있습니다.CommandInvokeError:명령이 발생한 예외:ClientException:에 연결되어 있지 않다. 오류에 연결하면 음성

0

질문

싫어 바보 소리에이(아마 할 일부)내가 진정으로 노력합니다. 나는 데 문제 d.py 음성입니다. 나는 로봇을 가진 음악 봇 기능,실행하려고 하면 명령 k!play (song name) 그것은 실패하면 그것을 말하고 접속하지 않은 목소리,연결된 경우 클라이언트 측에서,그리고 코드 사이드. 지 않아요 무슨 일이 일어나고 있는지 이해한다. 여기에는 코드 대한 전체적인 명령을 전체에서 오류 로그는:

@client.command(aliases=['p'])
async def play(ctx, *, query: t.Optional[str]):
    song_there = os.path.isfile("song.mp3")
    try:
        if song_there:
            os.remove("song.mp3")

    except PermissionError:
        return


    voice = discord.utils.get(client.voice_clients, guild=ctx.guild)
    if voice is None:
        voiceChannel = ctx.message.author.voice.channel
        await voiceChannel.connect()
        print("Connected to voice")
        voice = discord.utils.get(client.voice_clients, guild=ctx.guild)

    spotify_regex1 = r"https://open.spotify.com/track/(......................)"
    spotify_regex2 = r"https://open.spotify.com/track/(.......................)(si=)(................)"

    match = re.match(spotify_regex1, query)
    is_match1 = bool(match)
    match = re.match(spotify_regex2, query)
    is_match2 = bool(match)

    if is_match1 or is_match2 is True:
        print("Trying With Spotify")
        os.system(f"spotdl '{query}'")
        await ctx.send(f"`Now Playing:`  {query}")


    ydl_opts = {
        'format': 'bestaudio',
        'restrictfilenames': False,
        'noplaylist': True,
        'nocheckcertificate': True,
        'no_warnings': True,
        'default_search': 'auto',
        'source_address': '0.0.0.0',
    }

    try:
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            ydl.download([query])
            query_id = os.popen(f'youtube-dl --get-id "ytsearch:{query}"').read()
            title = os.popen(f'youtube-dl --get-title "ytsearch:{query_id}"').read()
            thumbnail_embed = os.popen(f'youtube-dl --get-thumbnail "ytsearch:{query_id}"').read()
            duration_embed = os.popen(f'youtube-dl --get-duration "ytsearch:{query_id}"').read()
            embed = discord.Embed(title="Now Playing", color=0xa00000)
            embed.set_thumbnail(url=thumbnail_embed)
            embed.add_field(name=title, value=f"`0:00 / {duration_embed}`", inline=True)
            embed.set_footer(text=f"Requested by {ctx.message.author}")
            await ctx.send(embed=embed)

    except:
        return

    for file in os.listdir("./"):
        if file.endswith(".mp3"):
            os.rename(file, "song.mp3")
            print("Changed mp3 to mp3")

    for file in os.listdir("./"):
        if file.endswith(".m4a"):
            os.rename(file, "song.mp3")
            print("Changed m4a to mp3")

    for file in os.listdir("./"):
        if file.endswith(".webm"):
            os.rename(file, "song.mp3")
            print("Changed webm to mp3")

    if song_there is False:
        time.sleep(5)
        await ctx.send("Song not found!")

    print("Playing File (or trying to)")

    voice.play(discord.FFmpegPCMAudio("song.mp3"))
    voice.source = discord.PCMVolumeTransformer(voice.source)
    voice.source.volume = 0.80

Connected to voice
[download] Downloading playlist: fuwa fuwa time
[youtube:search] query "fuwa fuwa time": Downloading page 1
[youtube:search] playlist fuwa fuwa time: Downloading 1 videos
[download] Downloading video 1 of 1
[youtube] jL8p9vteR5g: Downloading webpage
[youtube] Downloading just video jL8p9vteR5g because of --no-playlist
[youtube] jL8p9vteR5g: Downloading player f1ca6900
[download] Destination: K-ON! Fuwa Fuwa Time Yui and Mio Duet HD-jL8p9vteR5g.m4a
[download] 100% of 3.71MiB in 01:05                 
[ffmpeg] Correcting container in "K-ON! Fuwa Fuwa Time Yui and Mio Duet HD-jL8p9vteR5g.m4a"
[download] Finished downloading playlist: fuwa fuwa time
Changed m4a to mp3
Playing File (or trying to)
Ignoring exception in command play:
Traceback (most recent call last):
  File "C:\Users\..\PycharmProjects\kyoko test\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users..\PycharmProjects\kyoko test\main.py", line 850, in play
    voice.play(discord.FFmpegPCMAudio("song.mp3"))
  File "C:\Users\..\PycharmProjects\kyoko test\venv\lib\site-packages\discord\voice_client.py", line 555, in play
    raise ClientException('Not connected to voice.')
discord.errors.ClientException: Not connected to voice.

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

Traceback (most recent call last):
  File "C:\Users\..\PycharmProjects\kyoko test\venv\lib\site-packages\discord\ext\commands\bot.py", line 940, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\..\PycharmProjects\kyoko test\venv\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\..\PycharmProjects\kyoko test\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: Not connected to voice.

보다 그게 오류 로그

discord discord.py python
2021-11-23 14:15:32
1

최고의 응답

0

이 라인의 코드를 문제가 될 수 있습니다:

voice = discord.utils.get(client.voice_clients,guild=ctx.guild)

이를 위해성 클라이언트:

voice = ctx.message.guild.voice_client

나는 완전히 확실하지 않은 경우 이 문제는 그러나 희망을 작동합니다. 또한 오고 있는지 확인에 음성 채널을 실행하는 동안 명령입니다.

2021-11-23 20:52:38

당신은 내게 말할 수는 부분의 코드를 교체해야? 이 기능은 정의 많은 시간에서 서로 다른 매개변수,또한 그것을 변경하는 불 voice_channel 는 것입니다. @Roopesh-J
Jacob Shankman

아 죄송에 대한 변경 변수 이름,lemme 편집니다. 먼저 잘하는지 확인을 실행하려고 시도하 play 명령하는 동안 당신은 또한에서 음성 채널입니다. 대체하지 않는 코드만 줄을 추가 제안했에서 당신의 라인을 내가 한다. 그것은 기본적으로 다만 다른 방법으로 얻기의 목소리,클라이언트가 그렇게 생각할 수 있 이 방법으로 할 수 있습니다.
Roopesh-J

았다 그리고 그것은 여전히 나에게 오류를 예 나는 vc,나는 그것을 테스트하우지 않았을 것이 저에게"사용자에 없는 vc"오류가 있습니다.
Jacob Shankman

Dang,정말 이상해. I don't know what else 문제가 될 수 있습니다. 권하고 싶을 만드는 아마 다른 명령에는 연결되는 로봇은 음성 채널,할 수 있기 때문에 시각적으로 확인하는 경우에는 로봇이 채널에서 또는하지 않습니다.
Roopesh-J

이 코드를 사용에서는 오래된 로봇: voiceChannel = discord.utils.get(ctx.guild.voice_channels, name='General'). await voiceChannel.connect(). 나는 단지 그것을 사용에서 나의 일반적인 채널에 그래서 저는 바로 하드코딩된 이름입니다. 어쩌면 그것은 도움이 될 것입니다 하지만입니다.
Roopesh-J

내가 사용하는 사용하는 코드,그러나 나는 그것을 변경하는 모든 그냥 vc 에 대한 접근,내가 하려고 합이 작동하는지 확인합니다. (업데이트:그것은 여전히 최! 는 무슨 일이 일어나 나가지 이 오류가 있습니다.)
Jacob Shankman

Roopesh-J

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................