#Voicechannel (solved)

1 messages ยท Page 1 of 1 (latest)

queen marsh
#
const Discord = require('discord.js');
require("@discordjs/voice")

module.exports = {
    name: 'voiceStateUpdate',
    once: true,
    execute(oldMember, newMember, client) {

        let oldVoice = oldMember.voice.channel;
        let newVoice = newMember.voice.channel;

        const joinvcEmbed = new Discord.MessageEmbed()
            .setColor('GREEN')
            .setDescription(`${newMember} tilsluttede til **${newVoice}**`)
            .setTimestamp()

        const leavevcEmbed = new Discord.MessageEmbed()
            .setColor('RED')
            .setDescription(`${oldMember} forlod **${oldVoice}**`)
            .setTimestamp()

        const movevcEmbed = new Discord.MessageEmbed()
            .setColor('ORANGE')
            .setDescription(`${newMember} flyttede fra **${oldVoice}** til **${newVoice}**`)
            .setTimestamp()

        if (oldVoice != newVoice) {
            if (oldVoice == null) {
                client.channels.get('927902267909230642').send(joinvcEmbed)
            } else if (newVoice == null) {
                client.channels.get('927902267909230642').send(leavevcEmbed)
            } else {
                client.channels.get('927902267909230642').send(movevcEmbed)
            }
        }

    }
}
#

My event handler looks like this: ```js
module.exports = (client) => {
client.handleEvents = async (eventFiles) => {
for (const file of eventFiles) {
const event = require(../events/${file});
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
}
};
}

zealous shuttle
#

okay. so

amber flint
#

Hmm

wide sorrel
#

const gud = client.guilds.fetch('CHANNEL_ID_HERE')

zealous shuttle
#

the behaviour of your event is handled by previous joined channel (which is fired after leaving) and the channel joined

wide sorrel
#

fetch instead of cache.get

zealous shuttle
#

i can rewrite it a bit for you in accordance to my statement

queen marsh
#

Aha

zealous shuttle
#

oldMember and newMember are going to be undefined to which event is fired

#

u can't join and leave a channel at the same time (sadly). so one of these events are going to be undefined

queen marsh
#

Can I do ifs to check if they exist then?

zealous shuttle
#

also. call these event args oldState and newState

#

less confusing hehe

queen marsh
#

oldMember > oldState ?

zealous shuttle
#

nono

#
const Discord = require('discord.js');
require("@discordjs/voice")

module.exports = {
    name: 'voiceStateUpdate',

    execute(client, oldState, newState) {
        if (newState) {
            // boop biep i fire when someone joins a vc
        }

        if (oldState) {
            // no
        }
    }
}
queen marsh
zealous shuttle
#

basically. but i suggest not hoisting these values

#

let oldStateVC = oldState.voice.channel

#

inside of your if (oldState) {

#

u have to verify if they're falsey or not

#

omg istg

queen marsh
#

Okay you want my code to look like this right ```js
const Discord = require('discord.js');
require("@discordjs/voice")

module.exports = {
name: 'voiceStateUpdate',
once: true,
execute(client, oldState, newState) {

    if (newState) {
        let newStateVC = newState.voice.channel
    }
    if (oldState) {
        let oldStateVC = oldState.voice.channel
    }

    const joinvcEmbed = new Discord.MessageEmbed()
        .setColor('GREEN')
        .setDescription(`${newMember} tilsluttede til **${newVoice}**`)
        .setTimestamp()

    const leavevcEmbed = new Discord.MessageEmbed()
        .setColor('RED')
        .setDescription(`${oldMember} forlod **${oldVoice}**`)
        .setTimestamp()

    const movevcEmbed = new Discord.MessageEmbed()
        .setColor('ORANGE')
        .setDescription(`${newMember} flyttede fra **${oldVoice}** til **${newVoice}**`)
        .setTimestamp()

    if (oldVoice != newVoice) {
        if (oldVoice == null) {
            client.channels.get('927902267909230642').send(joinvcEmbed)
        } else if (newVoice == null) {
            client.channels.get('927902267909230642').send(leavevcEmbed)
        } else {
            client.channels.get('927902267909230642').send(movevcEmbed)
        }
    }

}

}

zealous shuttle
#

OKAY. WAIT

#

STAY HERE. DON'T MOVE

queen marsh
#

I'm not moving

zealous shuttle
#

I WILL BITE

queen marsh
#

Hmm?

#

I'm gonna cramp soon if I don't move soon

zealous shuttle
#

I KNOW

#
const Discord = require('discord.js');
require("@discordjs/voice");

module.exports = {
    name: 'voiceStateUpdate',
    once: true,

    execute(client, oldState, newState) {
        const logChannel = "805224882240749609";

        if (oldState.channel) {
            const leave = new Discord.MessageEmbed()
                .setColor('RED')
                .setDescription(`${oldState.member.user.tag} forlod **${oldState.channel}**`)
                .setTimestamp();

            oldState.guild.channels.cache.get(logChannel).send({ embeds: [leave] });

            return;
        }

        if (newState.channel) {
            const join = new Discord.MessageEmbed()
                .setColor('GREEN')
                .setDescription(`${newState.member.user.tag} tilsluttede til **${newState.channel}**`)
                .setTimestamp();

            newState.guild.channels.cache.get(logChannel).send({ embeds: [join] });

            return;
        }

        if (oldState.channel && newState.channel) {
            const move = new Discord.MessageEmbed()
                .setColor('ORANGE')
                .setDescription(`${newState.member.user.tag} flyttede fra **${oldState.channel}** til **${newState.channel}**`)
                .setTimestamp();

            newState.guild.channels.cache.get(logChannel).send({ embeds: [move] });
        }
    }
};
#

there u go. i'm going to go back to bed

#

๐ŸŽ‰

queen marsh
zealous shuttle
#

because logChannel should be the channel u have to set it as

#

const logChannel = "805224882240749609"; this is a random channel id. change it :)

queen marsh
#

OIh

zealous shuttle
#

dummy

queen marsh
#

Yee, whoops

zealous shuttle
#

there u go!!

#

u should be good

queen marsh
#

No actually you should have told me about that, that's your fault ahah

zealous shuttle
#

smhh neverrr

#

OKAY THREAD CLOSE MODERATORS

#

THANK U FOR UR ATTENDANCE

queen marsh
#

No not yet xd

zealous shuttle
#

oh?

#

๐Ÿ‘€

queen marsh
#

There's still a minor problem... When I join a voice channel it sends the leave embed and it sends nothing when I leave

zealous shuttle
#

what..

queen marsh
#

Mhm, I'm confused aswell

zealous shuttle
#

can u check dms?

queen marsh
#

Sure