discord.js事件voiceStateUpdate检测从将表单1通道移动到另一个通道

时间:2019-11-10 09:47:15

标签: node.js discord.js

问题1: 问题是,当用户从1个通道跳到另一个else if(oldUserChannel !== newUserChannel)时,该语句应该已经通过,但是问题是它没有通过该语句,而是离开了通道(简单来说,oldUserChannel!== newUserChannel无法正常工作) 问题2:我不知道为什么逻辑与我在堆栈溢出中发现的相反,请参见代码2

代码1:

const client = new Discord.Client();
module.exports = async (oldMember,newMember,message) => {

    if(newMember.user.bot) return;
    let newUserChannel = newMember.voiceChannel
    let oldUserChannel = oldMember.voiceChannel

    let newdate = new Date(newMember.joinedTimestamp)

    var log =  message.guild.channels.find(ch => ch.name.includes('voice-log')) || message.guild.channels.find(ch => ch.name.includes('member-log')) || message.guild.channels.find(ch => ch.name.includes('log')) || message.guild.channels.find(ch => ch.name.includes('logs')) || message.guild.channels.find(ch => ch.name.includes('general'));

    if(oldUserChannel === undefined && newUserChannel !== undefined) {
        log.send(`:small_red_triangle_down: <@${newMember.user.id}> Left a voice channel at ${newdate}`); 
    } else if(newUserChannel === undefined){
        log.send(`:white_check_mark: <@${newMember.user.id}> Joined a voice channel at ${newdate}`);
    }else if(oldUserChannel !== newUserChannel){
        log.send(`:arrow_right: <@${newMember.user.id}> Joined a voice channel at ${newdate}`);
    }

    }

代码2:

module.exports = async (oldMember,newMember,message) => {

    let newUserChannel = newMember.voiceChannel
    let oldUserChannel = oldMember.voiceChannel



    if(oldUserChannel === undefined && newUserChannel !== undefined) {

        // user joined the channel 
    } else if(newUserChannel === undefined){
        // user left the voice channel
    }

    }

有人能解释吗?

0 个答案:

没有答案