Home > Mobile >  How do I get user's current voice channel using discord.js?
How do I get user's current voice channel using discord.js?

Time:10-14

I'm trying to make my bot join the voice channel I'm currently using, but I can't seem to find how to get the message author's current voice channel.

So far I've seen suggestions to use message.member.voiceChannel but it doesn't work, message.member has no voiceChannel attribute.

I'm looking for something that works like this:

async execute(interaction) {
  const connection = joinVoiceChannel({
    channelId: interaction.member.voiceChannel,
    guildId: interaction.guild.id,
    adapterCreator: interaction.guild.voiceAdapterCreator,
  });
}

CodePudding user response:

It's message.member.voice.channel, not voiceChannel.

Even then, you don't provide an ID at channelId: interaction.member.voice.channel. The channel ID should be interaction.member.voice.channel.id:

const connection = joinVoiceChannel({
  channelId: interaction.member.voice.channel.id,
  guildId: interaction.guild.id,
  adapterCreator: interaction.guild.voiceAdapterCreator,
});

CodePudding user response:

Use interaction.member.voice.channel, interaction.guildId, and interaction.guild.voiceAdapterCreator

  • Related