我正在制作一个具有许多其他功能的不和谐音乐机器人,而且我一直都在遇到此错误
@client.command(pass_context=True)
async def join(ctx):
channel = ctx.message.author.voice.channel
connect = await channel.connect()
await connect(channel)
@client.command(pass_context=True)
async def play(ctx, url):
voice_client = ctx.guild.voice_client
server = ctx.message.guild
voice_client = ctx.guild.voice_client(server)
player = await voice_client.create_ytdl_player(url)
players[server.id] = player
player.start()
这是日志行/终端:
Ignoring exception in command play:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 55, in play
voice_client = ctx.guild.voice_client(server)
TypeError: 'NoneType' object is not callable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 855, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'NoneType' object is not callable
有人可以帮我这个忙吗?
答案 0 :(得分:3)
您正在尝试调用guild.voice_client
,这是一个属性,而不是我在文档中看到的方法。
由于公会对象没有与之关联的VoiceClient,因此出现'NoneType' object is not callable
错误。
如果您查看VoiceClient
的文档,就好像您是通过VoiceChannel.connect()
检索文档一样