gpt4 book ai didi

javascript - 在执行命令并移动到 Node.js 中的其他语音 channel 后,如何检查该人所在的语音 channel ID?

转载 作者:行者123 更新时间:2023-12-02 22:51:36 25 4
gpt4 key购买 nike

我需要在执行命令后检查该人所在的语音 channel ID。如果是在这个 channel 上,我希望机器人移动到另一个所需的 channel 。

      var idchannel = member.get.voiceChannelID;
if(idchannel === "ID"){
//command
// and i need to move this user to another channel.
}
else {
message.reply("You are not on the correct Channel.");
}

最佳答案

编辑:

从 Discord.js v12 开始,由于语音相关功能的变化,我原来的答案将不再有效。

假设您有 GuildMember 成员(member),您可以使用 member.voice 访问语音相关选项。通过那个VoiceState ,您可以引用VoiceState#channelID属性来访问VoiceChannel的ID该成员已连接到(如果有)。把它们放在一起,就是 member.voice.channelID

要将成员移动到特定 channel ,您可以使用 VoiceState#setChannel() 来执行此操作。方法,所以member.voice.setChannel(...)

更新后的代码如下所示:

const voiceChannelID = member.voice.channelID;
if (voiceChannelID === 'some channel ID') {
member.voice.setChannel('target channel ID') // you may want to await this, async fn required
.catch(console.error);
} else {
message.reply('You are not in the correct channel.') // see last comment
.catch(console.error);
}
<小时/>

原始版本 (v11):

您可以使用GuildMember.voiceChannel来引用用户连接到的语音 channel 。 。然后查看 channel 的id与预期 ID 对应的属性。

要将成员从一个语音 channel 移至另一个语音 channel ,您可以使用 GuildMember.setVoiceChannel()方法。

const voiceChannel = message.member.voiceChannel; // Keep in mind this may be undefined if
// they aren't connected to any channel.

if (voiceChannel && voiceChannel.id === "channel ID") {
message.member.setVoiceChannel(/* some other channel or ID */);
} else message.reply("You are not in the correct channel.");

确保发现您的 promise 中的任何错误。请参阅this MDN documentation .

关于javascript - 在执行命令并移动到 Node.js 中的其他语音 channel 后,如何检查该人所在的语音 channel ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58158637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com