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)
}
}
}
}
#Voicechannel (solved)
1 messages ยท Page 1 of 1 (latest)
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));
}
}
};
}
okay. so
Hmm
const gud = client.guilds.fetch('CHANNEL_ID_HERE')
the behaviour of your event is handled by previous joined channel (which is fired after leaving) and the channel joined
fetch instead of cache.get
i can rewrite it a bit for you in accordance to my statement
Aha
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
Can I do ifs to check if they exist then?
oldMember > oldState ?
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
}
}
}
Can I do this then ```js
let oldVoice;
let newVoice;
if (oldMember) {
oldVoice = oldMember.voice.channel;
}
if (newMember) {
newVoice = newMember.voice.channel;
}
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
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)
}
}
}
}
I'm not moving
I WILL BITE
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
๐
It says TypeError: Cannot read properties of undefined (reading 'send') on this line ```js
oldState.guild.channels.cache.get(logChannel).send({ embeds: [leave] });
because logChannel should be the channel u have to set it as
const logChannel = "805224882240749609"; this is a random channel id. change it :)
OIh
dummy
Yee, whoops
No actually you should have told me about that, that's your fault ahah
No not yet xd
There's still a minor problem... When I join a voice channel it sends the leave embed and it sends nothing when I leave
what..
Mhm, I'm confused aswell
can u check dms?
Sure