超时后语音通道不会被删除。 Discord.JS 12
Voice channel doesn't get deleted after timeout. Discord.JS 12
所以我目前正在进行最后的更改,以便将我的机器人从 discord.js 11.4 更新到 12。
但是,我 运行 解决了私人频道的另一个问题,在一定时间后没有被删除。
我尝试将 voiceChannel 更改为 voice.channel,但不幸的是它没有用。
这是我的代码:
bot.on("voiceStateUpdate", oldMember => {
deleteEmptyChannelAfterDelay(oldMember.voiceChannel);
});
function deleteEmptyChannelAfterDelay(voiceChannel, delayMS = 5000){
if(!voiceChannel) return;
if(voiceChannel.members.first()) return;
if(!voiceChannel.health) voiceChannel.health = 0;
voiceChannel.health += 1;
setTimeout(function(){ //queue channel for deletion and wait
if(!voiceChannel) return;
if(voiceChannel.members.first()) return;
voiceChannel.health -= 1;
if(voiceChannel.health > 0) return;
if(!voiceChannel.name.includes('\'s Room')) return;
voiceChannel.delete() //delete channel
.catch(error => console.log(error));
}, delayMS);
}
我尝试在 DJ 指南 and/or 论坛上寻求帮助,但找不到任何东西,所以我真的很感激任何可能的帮助!谢谢。
在 DiscordJS V12 中,voiceStateUpdate
event got changed. Instead of passing the paramters oldMember
and newMember
, it now passes oldState
and newState
which are instances of VoiceState. To get the channel the voiceStateUpdate
got triggered on, you no longer call member.voiceChannel
, but now call VoiceState.channel
.
因此,为了让您的代码正常工作,您必须将事件回调更改为以下内容:
bot.on("voiceStateUpdate", oldState => {
deleteEmptyChannelAfterDelay(oldState.channel);
});
所以我目前正在进行最后的更改,以便将我的机器人从 discord.js 11.4 更新到 12。
但是,我 运行 解决了私人频道的另一个问题,在一定时间后没有被删除。 我尝试将 voiceChannel 更改为 voice.channel,但不幸的是它没有用。
这是我的代码:
bot.on("voiceStateUpdate", oldMember => {
deleteEmptyChannelAfterDelay(oldMember.voiceChannel);
});
function deleteEmptyChannelAfterDelay(voiceChannel, delayMS = 5000){
if(!voiceChannel) return;
if(voiceChannel.members.first()) return;
if(!voiceChannel.health) voiceChannel.health = 0;
voiceChannel.health += 1;
setTimeout(function(){ //queue channel for deletion and wait
if(!voiceChannel) return;
if(voiceChannel.members.first()) return;
voiceChannel.health -= 1;
if(voiceChannel.health > 0) return;
if(!voiceChannel.name.includes('\'s Room')) return;
voiceChannel.delete() //delete channel
.catch(error => console.log(error));
}, delayMS);
}
我尝试在 DJ 指南 and/or 论坛上寻求帮助,但找不到任何东西,所以我真的很感激任何可能的帮助!谢谢。
在 DiscordJS V12 中,voiceStateUpdate
event got changed. Instead of passing the paramters oldMember
and newMember
, it now passes oldState
and newState
which are instances of VoiceState. To get the channel the voiceStateUpdate
got triggered on, you no longer call member.voiceChannel
, but now call VoiceState.channel
.
因此,为了让您的代码正常工作,您必须将事件回调更改为以下内容:
bot.on("voiceStateUpdate", oldState => {
deleteEmptyChannelAfterDelay(oldState.channel);
});