Discord.ext.คำสั่งของ.เกิดข้อผิดพลาด.CommandInvokeError:คำสั่งการเลี้ยงดูเป็นข้อยกเว้น:ClientException:ไม่มีการเชื่อมต่อต้องเสียง เกิดข้อผิดพลาดที่เชื่อมโยงกับเสียง

0

คำถาม

ฉันเกลียดที่ต้องฟังดูโง่เง่าอะไรเรื่องนี้(ฉันอาจจะทำบางอย่างฉันแท้จริงพยายามดีที่สุดของฉันแล้ว ผมก็มีปัญหาเรื่องกับ d.py เสียง ฉันมี bot กับดนตรี bot functionality และเมื่อฉันพยายามที่จะประมวลผลคำสั่ง 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-เจ
Jacob Shankman

อ่าขอโทษด้วยเรื่องการเปลี่ยนตัวแปรชื่อของ lemme แก้ไขนั้น งั้นคนแรกทำให้มั่นใจว่าคุณพยายามจะปกครอง play คำสั่งขณะที่คุณยังอยู่ในเสียงของช่อง ไม่แทนที่รหัสแต่ก็แค่เพิ่มเส้นผมแนะนำอยู่ใต้ของเส้นที่ฉันเคยพูดถึง. มันคือโดยทั่วไปต่างออกทางของได้เสียงของลูกค้าของฉันเลยคิดว่าอาจจะวิธีนี้มันจะได้ผล
Roopesh-J

ฉันทำมันและมันก็ยังทำให้ฉันข้อผิดพลาดและใช่ผมอยู่ใน vc,ฉันได้ทดลองมันและถ้าฉันไม่ได้มันจะทำให้ฉันเป็น"ของผู้ใช้ไม่อยู่ใน vc"ข้อผิดพลาด
Jacob Shankman

บ้าเอ๊ย,มันแปลกจริงๆ ฉันไม่รู้อะไรอื่นอีกอาจเป็นเหมือนไม่มีปัญหาอยู่เลยสินะ ฉันจะขอแนะนำอาจจะกำลังสร้างอีกคำสั่งมันเชื่อมโย bot ต้องเสียงช่องตั้งแต่คุณสามารถแค่ visually ตรวจสอบว่าที่ bot อยู่ในช่องหรือไม่
Roopesh-J

นี่คือรหัสฉันเคยจากหยุ bot: voiceChannel = discord.utils.get(ctx.guild.voice_channels, name='General'). await voiceChannel.connect(). ฉันใช้มันในของฉันท่านนายพลช่องทางดังนั้นฉันแค่พูดตรงๆเลย hardcoded องชื่อจนได้ บางทีมันอาจจะช่วยนะ
Roopesh-J

ฉันเคยใช้แบบนั้นเหมือนรหัสแต่ฉันเปลี่ยนมันเป็นอะไร vc แค่สำหรับการช่วยใช้งานฉันจะพยายามที่จะเห็นถ้ามันได้ผล (ปรับปรุง:มันยัง dosent! ฉันไม่เข้าใจ whats ขึ้นอย่างที่ฉันไม่เคยได้ข้อผิดพลาดนี้ด้วย)
Jacob Shankman

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

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