2017-05-22 1 views
0

Je cette fonction suivante:Obtenez le canal voix utilisateur id

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' 

Ma question est, comment puis-je obtenir l'identifiant de canal vocal de l'utilisateur qui a tapé la commande. Je sais comment obtenir l'identifiant du serveur, mais je ne trouve pas comment obtenir l'identifiant du canal vocal dans la documentation. Merci!

Répondre

1

Utiliser l'extension de commande et contexte:

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")