'Discord.js Voice Channel with Slash Commands

I want to create a Music Bot with the new Discord Slash Commands, but I don't know how to get the voice channel which the user is in.

With a normal Message-Command it's message.member.voice.channel.



Solution 1:[1]

Because interaction.member doesn't contain any voice information, i defined the voice channel as follows:

const guild = client.guilds.cache.get(interaction.guild_id)
const member = guild.members.cache.get(interaction.member.user.id);
const voiceChannel = member.voice.channel;

Solution 2:[2]

  const guild = client.guilds.cache.get(interaction.guild_id)
  const member = guild.member(interaction.member.user.id)
  const vchannel = member.voice.channel
  vchannel.join()

This is what worked for me.

Solution 3:[3]

You can use Interaction#member which will return the member who sent the interaction if it was sent in a guild, or null if it was not sent in a guild.

Solution 4:[4]

const voice_channel_id = interaction.guild.members.cache.get(interaction.member.user.id).voice.channelId

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nairol203
Solution 2 Dharman
Solution 3 Lioness100
Solution 4 Dave