python'NoneType'对象中的音乐不一致机器人错误,没有属性'create_ytdl_player'

时间:2018-09-05 22:03:28

标签: python discord discord.py

每当我运行此代码时:

@client.command(pass_context=True)
async def ranjaplay(ctx, url):
    server = ctx.message.server
    voice_client = client.voice_client_in(server)
    player = await voice_client.create_ytdl_player(url)
    players[server.id] = player
    player.start()     

它返回此错误:

Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\discord\ext\commands\bot.py", line 846, in process_commands
yield from command.invoke(ctx)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\discord\ext\commands\core.py", line 374, in invoke
yield from injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\site- 
packages\discord\ext\commands\core.py", line 54, in wrapped
raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'create_ytdl_player'

请帮助我解决此问题

1 个答案:

答案 0 :(得分:1)

该错误告诉我们client为None。为什么?让我们看一下docs

  

voice_client_in(服务器)

     

返回与服务器关联的语音客户端。   如果找不到语音客户端,则返回None。

简要检查一下cocs,我假设您必须先创建voiceclient(如果尚不存在)。这可以通过Client.join_voice_channel来完成。