Discordie.ext.comenzi.erori.CommandInvokeError: Comanda a ridicat o excepție: ClientException: Nu este conectat la voce. eroare atunci când este conectat la voce

0

Problema

Nu vreau să par prost pe asta (eu fac, probabil, pentru unii) sunt cu adevărat încercat meu cel mai bun. Am avut probleme cu d.py voce. Am un bot cu muzica bot funcționalitate, și când m-am încercați să executați comanda k!play (song name) Ea nu spune că nu este conectat la voce, atunci când este conectat pe partea de client, și codul parte. Nu înțeleg ce se întâmplă. Aici este codul pentru întreaga comandă, și întregul jurnal de eroare sub care:

@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.

Decât asta e jurnal de eroare

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

Cel mai bun răspuns

0

Această linie de cod ar putea fi problema:

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

Încercați acest lucru pentru obtinerea vocea clientului:

voice = ctx.message.guild.voice_client

Eu nu sunt în totalitate sigur dacă aceasta problema, dar sper că funcționează. Oh, de asemenea, asigurați-vă că sunteți într-o voce de canal în timp ce rulează comanda.

2021-11-23 20:52:38

Poți să-mi spui care parte din cod ar trebui să fie înlocuit? această funcție este definită de mai multe ori în diferite parametri, ți schimbă, de asemenea, să fie numit voice_channel care este confuz. @Roopesh-J
Jacob Shankman

Ah scuze pentru schimbarea nume de variabilă, lasă-mă să editați asta. Ei bine, în primul rând asigurați-vă că încercarea de a rula play comandă în timp ce sunteți, de asemenea, în canalul de voce. Nu înlocuiți codul, dar trebuie doar să adăugați linia i-am sugerat sub linia care le-am menționat. Acesta este de fapt doar un alt mod de a obține vocea clientului, așa că am crezut că poate în acest fel s-ar lucra.
Roopesh-J

Am făcut asta și mi-a dat eroare, și da, eu sunt într-un vc, am testat-o și Dacă nu mi-ar da un "Utilizatorul nu este în vc" eroare.
Jacob Shankman

Dang, asta e foarte ciudat. Nu știu ce altceva ar putea fi problema. Mi-ar recomanda poate crea o altă comandă care tocmai se conectează la bot la canalul de voce, deoarece puteți doar să verificați vizual dacă bot este în canal sau nu.
Roopesh-J

Acesta este codul ce l-am folosit la o vârstă bot: voiceChannel = discord.utils.get(ctx.guild.voice_channels, name='General'). await voiceChannel.connect(). Am folosit-o numai în general canalului deci cred hardcoded numele. Poate va ajuta totusi.
Roopesh-J

Am folosit pentru a folosi exact codul, dar am schimbat-o să fie nici vc doar pentru accesibilitate, voi încerca să văd dacă merge. (Update: inca mai urâtă! Nu inteleg ce se intampla ca nu am mai primit eroarea asta.)
Jacob Shankman

Roopesh-J

În alte limbi

Această pagină este în alte limbi

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