问题
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