Discord.py机器人无法连接到语音通道

时间:2020-06-09 10:12:02

标签: python discord.py discord.py-rewrite

我正在尝试使用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

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

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:-2)

编辑: 完整解决方案:

@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):