python - Discord.py 机器人不离开语音 channel

标签 python discord discord.py

我正在尝试编写一个discord.py 机器人,但在尝试让机器人离开语音 channel 时遇到了问题。我一直在网上查找,但未能找到解决我的问题的有效解决方案。

我正在使用的库:

import discord
import asyncio
import random
import time
import youtube_dl
from discord.ext import commands
from discord.ext.commands import Bot
from discord import Game
from discord import opus

我正在使用的代码:

@client.command(pass_context=True)
async def summon(ctx):
    channel = ctx.message.author.voice.voice_channel
    vc = await client.join_voice_channel(channel)

@client.command(name = "check", pass_context=True)
async def check(ctx):
    server = ctx.message.server
    if client.is_voice_connected(server):
        await client.say("Yes")
    else:
        await client.say("No")

@client.command(pass_context=True)
async def leave(ctx):
    for x in client.voice_clients:
        if(x.server == ctx.message.server):
            return await x.discconect()
    return await client.say("Mission Failed."

我收到的错误消息:

Ignoring exception in command summon
Traceback (most recent call last):

  File "C:\Program Files (x86)\Python36-32\lib\site-packages\discord\ext\commands\core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)

  File "A:/Python/MossyBot/Bot Version 1.0.py", line 53, in summon
    vc = await client.join_voice_channel(channel)

  File "C:\Program Files (x86)\Python36-32\lib\site-packages\discord\client.py", line 3209, in join_voice_channel
    voice = VoiceClient(**kwargs)

  File "C:\Program Files (x86)\Python36-32\lib\site-packages\discord\voice_client.py", line 217, in __init__
    raise RuntimeError("PyNaCl library needed in order to use voice")

RuntimeError: PyNaCl library needed in order to use voice

最佳答案

最后一行告诉您需要了解的内容。

PyNaCL 运行 pip 安装,这是大多数语音功能所必需的,如下所示:

pip install pynacl

关于python - Discord.py 机器人不离开语音 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53145128/

相关文章:

python - 通过删除 NaN 并向左移动值以减少列数来压缩 pandas DataFrame 中的数据

javascript - Discord.js 从 message.content 获取 Unicode 表情符号

javascript - Discord.js:检测来自 Webhook 的消息

python - Discord py bot 限制玩家对投票的一个 react

Python:为什么我使用 super() 而不是使用显式父类(super class)名称时会出现异常?

python - 为什么 QPrinterDialog 不能在 PySide 中正确采用每台打印机的默认选项?

Python Pandas : How to split a column on left parenthesis and remove numbers from a column of dataframe

javascript - 如何制作歌曲循环/如何制作循环命令

python - 如何处理 `MissingRequiredArgument`错误

python - Discord.py:wait_for ('reaction_add')未按预期工作