克隆DiscordJS后获取频道ID

时间:2019-09-25 07:31:11

标签: javascript discord.js

我正在使用DiscordJS机器人,我想将用户移至我克隆的频道。为此,我需要获取频道的ID,但我不知道该怎么做。

bot.on("voiceStateUpdate", (oldMember, newMember) => {
  let newUserChannelID = newMember.voiceChannelID
  let newUserName = newMember.username
  let channel = bot.channels.get("626043862397354025")

  if(newUserChannelID == "534437314231926804") {
    channel.clone('Salon privé de ' + newUserName, true, false, 'Création channel privé.')
    .then(clone => console.log(`Clone du channel ${channel.name} pour faire un nouveau channel nommé ${clone.name}`))
    .catch(console.error);

    let newPrivateChannel = clone.voiceChannelID

    newMember.setVoiceChannel(newPrivateChannel)
  }
});

clone方法将返回GuildChannel对象。

你有个主意吗?

1 个答案:

答案 0 :(得分:1)

更像这样:

if(newUserChannelID == "534437314231926804") {
    channel.clone('Salon privé de ' + newUserName, true, false, 'Création channel privé.')
    .then(clone => {
               console.log(`Clone du channel ${channel.name} pour faire un nouveau channel nommé ${clone.name}`)
               // clone is available
               let newPrivateChannel = clone.voiceChannelID

               newMember.setVoiceChannel(newPrivateChannel)
    })
    .catch(console.error);

  }