2
votes

I'm working on a discord bot and when the user react to a bot message, first it should check if the user is connected to a voice channel and if it is, the bot should join the voice channel, i'm using awaitReactions and it only returns reaction and user.

How can i get member voice channel with user or reaction?

1

1 Answers

2
votes

Firstly, to get a GuildMember from a User, there are a few options.

  • Use Guild#member. This function has already been removed in the master branch, and probably won't be included in future versions, but it's currently still very usable.
const user = ...
const guild = ...
const member = guild.member(user);
const user = ...
const guild = ...
const member = guild.members.cache.get(user.id);

You can find the VoiceChannel the member is in through their VoiceState. Every VoiceState has a channel property referencing the voice channel they are currently in, or null if no channel was found.

const member = ...
const channel = member.voice.channel;

if (channel) channel.join();