【问题标题】:Discord.py Bot Not Leaving Voice ChannelDiscord.py 机器人不离开语音频道
【发布时间】:2019-04-08 06:22:41
【问题描述】:

我正在尝试编写一个 discord.py 机器人,但在尝试让机器人离开语音频道时遇到了问题。我一直在网上寻找,但无法找到解决问题的有效方法。

我正在使用的库:

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
  • 您在倒数第二行拼错了 disconnect,并且在最后一行代码中缺少一个 )。会不会是这个问题?

标签: python discord discord.py


【解决方案1】:

最后一行告诉你你需要知道什么。

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

pip install pynacl

【讨论】:

    猜你喜欢
    • 2018-06-16
    • 2021-04-24
    • 2020-10-24
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 2020-08-30
    • 2022-01-04
    • 2021-11-19
    相关资源
    最近更新 更多