拥有用户ID时,如何设置用户的语音通道?

时间:2020-05-21 04:24:43

标签: javascript node.js bots discord.js

当用户与西瓜表情符号反应时,我正在尝试移动用户。

使用user.id.voice.setChannel("712142435794550894"); 时可以获取他们的用户ID,但不适用于

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

我得到的错误是:

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");
  }
});

这是我正在使用的代码:

 func saveContactfor(accountID:String,data:[Array],isAddedFromDevice:Bool) {
    let request:NSFetchRequest<Account> = Account.fetchRequest()

           do {
               let searchResults = try managedObjectContext.fetch(request)
                   for account in searchResults {

                      if account.account_Id == accountID {
                       print("ID found in already saved Accounts")
                        for contact in data {

                            account.contacts?.adding(contact.dictionary) //contact.dictionary-> i have written a utils method to convert an object array to [[String:String]] which is an array of dictionaries
                        }
                        try managedObjectContext.save()
                      }


                    }


           print("Contacts Updated")
           } catch {
            print("Error in saving contacts from api to coredata")
           }
}

如何根据用户ID移动用户?

1 个答案:

答案 0 :(得分:0)

GuildMember上似乎存在语音(至少从discord.js 12开始),所以您需要这样做:

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