【发布时间】:2020-10-19 14:13:25
【问题描述】:
我想知道是否有可能知道是否有任何成员连接到 discord.js v12.2.0 中的特定语音通道。最近几天我一直在坚持这个问题。如果你有任何线索,请告诉我。
【问题讨论】:
标签: javascript discord discord.js
我想知道是否有可能知道是否有任何成员连接到 discord.js v12.2.0 中的特定语音通道。最近几天我一直在坚持这个问题。如果你有任何线索,请告诉我。
【问题讨论】:
标签: javascript discord discord.js
我不确定您是否想知道该成员是否连接到 VoiceChannel 或收听 voiceStateUpdate 事件,因此我将介绍这两种情况。
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.`);
};
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}.`)
};
});
【讨论】: