【问题标题】:User connected to voice channel?用户连接到语音通道?
【发布时间】:2020-10-19 14:13:25
【问题描述】:

我想知道是否有可能知道是否有任何成员连接到 discord.js v12.2.0 中的特定语音通道。最近几天我一直在坚持这个问题。如果你有任何线索,请告诉我。

【问题讨论】:

标签: javascript discord discord.js


【解决方案1】:

我不确定您是否想知道该成员是否连接到 VoiceChannel 或收听 voiceStateUpdate 事件,因此我将介绍这两种情况。

检查成员是否连接到 VoiceChannel

const Guild = client.guilds.cache.get("GuildID"); // Getting the guild.
const Member = Guild.members.cache.get("UserID"); // Getting the member.

if (Member.voice.channel) { // Checking if the member is connected to a VoiceChannel.
    // The member is connected to a voice channel.
    // https://discord.js.org/#/docs/main/stable/class/VoiceState
    console.log(`${Member.user.tag} is connected to ${Member.voice.channel.name}!`);
} else {
    // The member is not connected to a voice channel.
    console.log(`${Member.user.tag} is not connected.`);
};

监听 voiceStateUpdate 事件

client.on("voiceStateUpdate", (oldVoiceState, newVoiceState) => { // Listeing to the voiceStateUpdate event
    if (newVoiceState.channel) { // The member connected to a channel.
        console.log(`${newVoiceState.member.user.tag} connected to ${newVoiceState.channel.name}.`);
    } else if (oldVoiceState.channel) { // The member disconnected from a channel.
        console.log(`${oldVoiceState.member.user.tag} disconnected from ${oldVoiceState.channel.name}.`)
    };
});

【讨论】:

  • 我知道这一点,我要问的是我不知道机器人如何继续跟踪特定频道是否连接了任何成员。我想做一个事情,比如当有人连接到语音通道 1 时,机器人显示语音通道 2。如果语音通道的成员断开连接,则隐藏通道 2。如果有成员连接通道 1 或 2,则显示通道3
  • 我无法理解您的问题。我想您是在问是否可以检查是否有任何用户连接到某个频道?对吗?
  • 是的,没错。我希望机器人继续检查某个频道是否有任何成员连接。
  • 您可以使用VoiceChannel.members(收藏)查看是否有会员连接到频道。
猜你喜欢
  • 2019-09-23
  • 2021-09-18
  • 2022-01-05
  • 2021-02-19
  • 2017-07-31
  • 1970-01-01
  • 2021-07-01
  • 2020-02-19
  • 2021-04-29
相关资源
最近更新 更多