Python 获取用户语音通道id

Python 获取用户语音通道id,python,discord.py,Python,Discord.py,我有以下功能: async def play_youtube_url(youtube_url): channel = client.get_channel('VOICE_CHANNEL_ID') if youtube_url.startswith('https://www.youtube.com/watch?v='): voice = await client.join_voice_channel(channel) player = await voice.create_ytdl

我有以下功能:

async def play_youtube_url(youtube_url):
channel = client.get_channel('VOICE_CHANNEL_ID')
if youtube_url.startswith('https://www.youtube.com/watch?v='):
    voice = await client.join_voice_channel(channel)
    player = await voice.create_ytdl_player(youtube_url)
    player.start()
else:
    return 'URL_ERROR'

我的问题是,如何获取键入命令的用户的语音频道id。我知道如何获取服务器id,但在文档中找不到如何获取语音频道id。谢谢

使用命令扩展名和上下文:

import discord
from discord.ext import commands

...

client = commands.Bot(command_prefix="!")
@client.command(pass_context=True)
async def play_youtube_url(self, ctx, youtube_url):
    channel = ctx.message.author.voice.voice_channel 
    # http://discordpy.readthedocs.io/en/latest/api.html#discord.Member.voice
    # http://discordpy.readthedocs.io/en/latest/api.html#discord.VoiceState.voice_channel
    if youtube_url.startswith('https://www.youtube.com/watch?v='):
        voice = await client.join_voice_channel(channel)
        player = await voice.create_ytdl_player(youtube_url)
        player.start()
    else:
        return 'URL_ERROR'

...

client.run("token")