简体   繁体   中英

Discord.py - How would I get the ID of a Voice Channel?

I'm trying to get the ID of the author's voice channel. I'm trying to get it to make a link that you can click to go onto a full voice channel (if that makes sense):

@client.command()
async def fullv(ctx):

 guild=ctx.message.guild
 author=ctx.message.author
 channel = 
 vc=f"https://discordapp.com/{guild.id}/{channel.id}"

 embed=discord.Embed(title="Join Full Voice", url=vc, description="Full voice is a DM voice chat in a Discord Server!", color=0x00ff40)

 await ctx.send(embed=embed)

Without {channel.id} in vc=f"https://discordapp.com/{guild.id}/{channel.id}" it works fine but then you can't view the voice channel

ctx.author.voice is the VoiceState of the author, which has a channel attribute representing the VoiceChannel that member is in:

if ctx.author.voice and ctx.author.voice.channel:
    channel = ctx.author.voice.channel
else:
    await ctx.send("You are not connected to a voice channel")
    return

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM