Error on music discord bot in python 'NoneType' object has no attribute 'create_ytdl_player'

孤者浪人 提交于 2021-01-29 14:21:46

问题


When ever i run this code:

@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()     

it returns with this error:

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'

Please help me fix this


回答1:


the error tells us that client is None. why? let's look at the docs:

voice_client_in(server)

Returns the voice client associated with a server. If no voice client is found then None is returned.

Checking the cocs briefly, i assume you have to create the voiceclient first, if it doesn't exist yet. this can be done with Client.join_voice_channel.



来源:https://stackoverflow.com/questions/52193942/error-on-music-discord-bot-in-python-nonetype-object-has-no-attribute-create

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!