【发布时间】: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