简体   繁体   中英

How do I set a user's voice channel when I have the user's id?

I'm trying to move a user when they react with a watermelon emoji to my embed.

I can get their user id when I use user.id , but it doesn't work with

user.id.voice.setChannel("712142435794550894");

The error I'm getting is:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'setChannel' of undefined

This is the code I'm using:

const check = new MessageEmbed()
  .setTitle("AFK CHECK")
  .setColor(0xFF0000)
  .setDescription("React with a `watermelon 🍉` PLS");

message.channel.send(check).then(sentEmbed => {
  sentEmbed.react("🍉");
})

bot.on('messageReactionAdd', async(reaction, user) => {
  let msg = reaction.message,
    emoji = reaction.emoji;
  const person = user.id;
  if (emoji.name == '🍉' && user.id != "711388151960043582") {
    message.channel.send("HI")
    user.id.voice.setChannel("712142435794550894");
  }
});

How do I move the users based on their id?

Looks like voice exists on GuildMember (at least as of discord.js 12), so you'll need to do:

message.guild.member(user.id).voice.setChannel("712142435794550894");

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