我想知道是否可以知道discord.js v12.2.0中是否有任何成员连接到特定的语音通道。最近几天,我一直在坚持这个问题。请告诉我您是否有任何线索。
答案 0 :(得分:2)
我不确定您是否想知道成员 是否已连接到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}.`)
};
});