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.
};
});
添加回答
举报