1 回答

TA貢獻1883條經驗 獲得超3個贊
如果用戶正AFK
從另一個頻道移動到該頻道,oldUserChannel
將被定義為VoiceChannel
.
您應該檢查是否newUserChannel
存在(如果是這樣,我們知道用戶仍然連接到 a?VoiceChannel
,并檢查頻道的 ID/名稱是否等于“AFK”/“頻道 ID”。
注意:我鼓勵你切換到 Discord JS v12。
client.on("voiceStateUpdate", (oldMember, newMember) => {
? ? if (!newMember.voiceChannel) return false; // The GuildMember is not in a VoiceChannel.
? ? if (newMember.voiceChannel.guild.id !== "GUILD ID") return false; // Making sure this works in a certain Guild. I don't think you want this to happen in every Guild your bot is in which has a VoiceChannel called "AFK".?
? ? if (newMember.voiceChannel.name == "AFK" && newMember.id == "USER ID") { // Checking if the channel's name is AFK and making sure the user is the one you want to disconnect.
? ? ? ? newMember.setVoiceChannel(null);
? ? ? ? // I'm not sure if Discord JS v11 has a method of disconnecting the user from a VoiceChannel.
? ? ? ? // But setting the voice channel to null will work.
? ? };
});
添加回答
舉報