TypeError:“ NoneType”对象无法通过Discord API和youtube_dl调用

问题描述

我正在制作一个具有许多其他功能的不和谐音乐机器人,而且我一直都在遇到此错误

@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

有人可以帮我这个忙吗?

解决方法

您正在尝试调用guild.voice_client,这是一个属性,而不是我在文档中看到的方法。

由于公会对象没有与之关联的VoiceClient,因此出现'NoneType' object is not callable错误。

如果您查看VoiceClient的文档,就好像您是通过VoiceChannel.connect()检索文档一样

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...