Logs - Discordjs

Hello, I have logs when a member changes vocal room but how can I put logs if they are moved?
7 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
Aiwoz
Aiwoz11mo ago
I couldn't find anything useful in the docs and on the internet. My code :
const { EmbedBuilder } = require(`discord.js`);
const { log_channel } = require(`../config.json`);

module.exports = {
name: 'voiceStateUpdate',
execute(oldState, newState) {
const oldChannel = oldState.channel;
const newChannel = newState.channel;

if (oldChannel === newChannel) return;

if (!oldChannel && newChannel) {
console.log(`${newState.member.user.displayName} (${newState.member.user.id}) a rejoint le salon vocal ${newChannel.name}.`);
const joinLog = new EmbedBuilder()
.setColor(`#00FF00`)
.setTitle(`Un membre vient de rejoint un salon vocal.`)
.setDescription(`Salon: ${newChannel.name} \n Membre: ${newState.member.user.displayName} \n ID: ${newState.member.user.id}`)
.setTimestamp();
newState.guild.channels.cache.get(log_channel).send({embeds: [joinLog]});
}
if (oldChannel && !newChannel) {
console.log(`${oldState.member.user.displayName} (${oldState.member.user.id}) a quitté le salon vocal ${oldChannel.name}.`);
const leaveLog = new EmbedBuilder()
.setColor(`#FF0000`)
.setTitle(`Un membre vient de quitter un salon vocal.`)
.setDescription(`Salon: ${oldChannel.name} \n Membre: ${oldState.member.user.displayName} \n ID: ${oldState.member.user.id}`)
.setTimestamp();
oldState.guild.channels.cache.get(log_channel).send({embeds: [leaveLog]});
}
if (oldChannel && newChannel) {
console.log(`${newState.member.user.displayName} (${newState.member.user.id}) a changé de salon vocal. ${oldChannel.name} => ${newChannel.name}`);
const switchLog = new EmbedBuilder()
.setColor(`#00FF00`)
.setTitle(`Un membre vient de changer de salon vocal.`)
.setDescription(`Ancien Salon: ${oldChannel.name} \n Nouveau Salon: ${newChannel.name} \n Membre: ${newState.member.user.displayName} \n ID: ${newState.member.user.id}`)
.setTimestamp();
newState.guild.channels.cache.get(log_channel).send({embeds: [switchLog]});
}
},
};

const { EmbedBuilder } = require(`discord.js`);
const { log_channel } = require(`../config.json`);

module.exports = {
name: 'voiceStateUpdate',
execute(oldState, newState) {
const oldChannel = oldState.channel;
const newChannel = newState.channel;

if (oldChannel === newChannel) return;

if (!oldChannel && newChannel) {
console.log(`${newState.member.user.displayName} (${newState.member.user.id}) a rejoint le salon vocal ${newChannel.name}.`);
const joinLog = new EmbedBuilder()
.setColor(`#00FF00`)
.setTitle(`Un membre vient de rejoint un salon vocal.`)
.setDescription(`Salon: ${newChannel.name} \n Membre: ${newState.member.user.displayName} \n ID: ${newState.member.user.id}`)
.setTimestamp();
newState.guild.channels.cache.get(log_channel).send({embeds: [joinLog]});
}
if (oldChannel && !newChannel) {
console.log(`${oldState.member.user.displayName} (${oldState.member.user.id}) a quitté le salon vocal ${oldChannel.name}.`);
const leaveLog = new EmbedBuilder()
.setColor(`#FF0000`)
.setTitle(`Un membre vient de quitter un salon vocal.`)
.setDescription(`Salon: ${oldChannel.name} \n Membre: ${oldState.member.user.displayName} \n ID: ${oldState.member.user.id}`)
.setTimestamp();
oldState.guild.channels.cache.get(log_channel).send({embeds: [leaveLog]});
}
if (oldChannel && newChannel) {
console.log(`${newState.member.user.displayName} (${newState.member.user.id}) a changé de salon vocal. ${oldChannel.name} => ${newChannel.name}`);
const switchLog = new EmbedBuilder()
.setColor(`#00FF00`)
.setTitle(`Un membre vient de changer de salon vocal.`)
.setDescription(`Ancien Salon: ${oldChannel.name} \n Nouveau Salon: ${newChannel.name} \n Membre: ${newState.member.user.displayName} \n ID: ${newState.member.user.id}`)
.setTimestamp();
newState.guild.channels.cache.get(log_channel).send({embeds: [switchLog]});
}
},
};

Yes, but how can I check if he is the one changing the channel or if he is being moved.
Solo™
Solo™11mo ago
Oh my compare the sessionID property of the oldState and newState maybe If the sessionID remains the same, the user switched channels on their own.
Aiwoz
Aiwoz11mo ago
Ah, but is it better to use Audit Logs for the other logs? (When a member leaves or joins the server and when he leaves or joins a voice room. Ok, thanks Oops, I forgot. 🙂
Solo™
Solo™11mo ago
hmm, shit, then audit logs sadboi
Aiwoz
Aiwoz11mo ago
😉 Thank you and have a nice day or night if you are in E.U. 😴
Solo™
Solo™11mo ago
<:orange_smile:976628301256867900>
Want results from more Discord servers?
Add your server