【发布时间】:2020-09-12 10:13:16
【问题描述】:
Traceback (most recent call last):
File "C:\Users\Pradeep Tejwani\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Pradeep Tejwani\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 797, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Pradeep Tejwani\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 92, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: RuntimeError: PyNaCl library needed in order to use voice
这是我的错误,即使我同时安装了 python 库 pynacl 和 discord.py[voice]。我尝试了很多次,但仍然出现同样的错误。我什至将我的库更新到了较新的版本,但没有任何改变。
代码:
@bot.command()
async def join(ctx):
channel = ctx.message.author.voice.channel
voice = get(bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
await voice.disconnect()
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
print(f"The bot has connected to {channel}\n")
await ctx.send(f"Joined {channel}")
#leave cmd
@bot.command()
async def leave(ctx):
channel = ctx.message.author.voice.channel
voice = get(bot.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.disconnect()
print(f"The bot has left {channel}")
await ctx.send(f"Left {channel}")
else:
print("Bot was told to leave voice channel, but was not in one")
await ctx.send("Don't think I am in a voice channel")
【问题讨论】:
-
你确定你运行脚本的解释器与你使用 pip 安装包时使用的解释器相同吗?
-
我使用vs code(虚拟工作室代码)运行脚本和cmd提示安装包
-
从两个终端(CMD 和 VScode)运行命令
where python并确保它们指向同一个地方 -
当我在 vs 代码中运行 Python 时,我什么也得不到
-
好的,等一下,我在 cmd 和 vs 代码中的结果是一样的