Discord.py 机器人不会连接到语音通道

Discord.py bot won't connect to a voice channel

我正在尝试用我的 discord 机器人发出一些基本的音乐命令,但我似乎无法让机器人连接到 vc。这是我试过的代码:


    @commands.command(pass_context=True)
    async def join(self, ctx):
        channel = ctx.author.voice.channel
        if channel: 
            print(channel.id)
            await channel.connect(reconnect=True) 
        else:
            await ctx.send('bruh you arent in a vc')

有谁知道为什么这不起作用?此外,这是我的进口商品,以防它们出现问题(无论出于何种原因):

import asyncio
import youtube_dl
import shutil
import ffmpeg 
import os
from discord.utils import get
from discord.ext import commands
import discord
import datetime

如果有人知道这个问题,以及我该如何解决,我将不胜感激。

编辑: 完整解决方案:

@client.command()
async def join(ctx):
    channel = ctx.author.voice.channel
    if channel:
        print(channel.id)
        await channel.connect(reconnect=False)
    else:
        await ctx.send('bruh you arent in a vc')

快速修复

改变

async def join(self, ctx):

收件人:

async def join(ctx):

尝试安装:pip install discord.py[voice]

也许你遇到了这个问题:discord.ext.commands.errors.CommandInvokeError: Command raised an exception: RuntimeError: PyNaCl library needed in order to use voice