【问题标题】:Get channel ID after cloning DiscordJS克隆 DiscordJS 后获取频道 ID
【发布时间】:2019-09-25 17:13:51
【问题描述】:

我正在开发一个 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 对象。

你有什么想法吗?

【问题讨论】:

  • ... let newPrivateChannel = clone
  • 我正在尝试,谢谢!
  • @Estradiaz 我找了它,但我不知道如何确定它的范围,我是 javascript 新手...
  • 尝试理解这一点:developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… 并将其与他的线路 .then(clone => console.log(Clone du ...` 进行比较 - 还要检查此 developer.mozilla.org/en-US/docs/Glossary/Scope - 如果仍有不清楚的地方,请询问;)跨度>
  • @Estradiaz 喜欢这样吗? if(newUserChannelID == "534437314231926804") { channel.clone('Salon privé de ' + newUserName, true, false, 'Création channel privé.') .then(clone => this.newPrivateChannel = clone.id) .catch(console.error); newMember.setVoiceChannel(newPrivateChannel) }我真的不知道我的错误在哪里大声笑

标签: javascript discord.js


【解决方案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);

  }

【讨论】:

  • 忘了谢谢你,哈哈,它现在正在工作,谢谢你的帮助。如果用户现在离开频道,我正在寻找一种删除频道的方法!
猜你喜欢
  • 2020-11-26
  • 1970-01-01
  • 2020-08-12
  • 1970-01-01
  • 2021-01-25
  • 2019-12-28
  • 2020-07-26
  • 2022-07-06
  • 1970-01-01
相关资源
最近更新 更多