Discord.py: join_voice_channel() not working

Created on 23 Oct 2017  路  9Comments  路  Source: Rapptz/discord.py

This should be a command to let the bot join the author's voice channel:

@asyncio.coroutine
@bot.command(pass_context=True)
async def sfx(ctx):
voice_channel = ctx.message.author.voice.voice_channel
await client.join_voice_channel(voice_channel)
print("Joined channel" + str(voice_channel))

The error is similar to this one: https://github.com/Rapptz/discord.py/issues/814

`
Ignoring exception in command sfx
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/discord/ext/commands/core.py", line 50, in wrapped
ret = yield from coro(args, *kwargs)
File "bot.py", line 244, in sfx
vc = await client.join_voice_channel(voice_channel)
File "/usr/local/lib/python3.5/site-packages/discord/client.py", line 3187, in join_voice_channel
session_id_future = self.ws.wait_for('VOICE_STATE_UPDATE', session_id_found)
AttributeError: 'NoneType' object has no attribute 'wait_for'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/discord/ext/commands/bot.py", line 846, in
process_commands
yield from command.invoke(ctx)
File "/usr/local/lib/python3.5/site-packages/discord/ext/commands/core.py", line 374, in invoke
yield from injected(ctx.args, *ctx.kwargs)
File "/usr/local/lib/python3.5/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 'wait_for'
`

Most helpful comment

  1. You don't need both async def and @asyncio.coroutine, if you are using >3.4 you can use either (with async def being preferred, see here.)
  2. client.ws should only be None before the bot logs in. From your code, it looks like you are using multiple Clients at once, with only one of them being logged in.

For reference, every commands.Bot is also a discord.Client. You don't need to use both of them.
You should remove your client and instead use bot for all of the client calls, In your instance:

- await client.join_voice_channel(voice_channel)
+ await bot.join_voice_channel(voice_channel)

Remember that this applies for all references that include a Client, so you may need to amend other code around your bot to follow this as well.

All 9 comments

iirc member (aka author) has no .voice_channel attribute, i think you need member.voice.voice_channel

You mean channel = ctx.message.author.voice.voice_channel?

Yes, that is what you should change it to. Try it and if it works, mark the issue as closed.

I get the same error

It will be None if the author of the message is not in a voice channel.

If I'm not in a voice channel, I get the channel passed must be a voice channel

I tried another way to get it working, still get the same error.

The main error is: AttributeError: 'NoneType' object has no attribute 'wait_for'

  1. You don't need both async def and @asyncio.coroutine, if you are using >3.4 you can use either (with async def being preferred, see here.)
  2. client.ws should only be None before the bot logs in. From your code, it looks like you are using multiple Clients at once, with only one of them being logged in.

For reference, every commands.Bot is also a discord.Client. You don't need to use both of them.
You should remove your client and instead use bot for all of the client calls, In your instance:

- await client.join_voice_channel(voice_channel)
+ await bot.join_voice_channel(voice_channel)

Remember that this applies for all references that include a Client, so you may need to amend other code around your bot to follow this as well.

Thank you very much!

Was this page helpful?
0 / 5 - 0 ratings