the_1king
the_1king
DIAdiscord.js - Imagine an app
Created by the_1king on 5/1/2024 in #djs-questions
Log all events into server channel
Hey! I'm trying to write a simple script that will log events into a server channel. Seems simple...but it's just not working for me. Anyone do something like this?
const logChannelId = '1024461076689080370';

const logger = function(interaction){
const logChannel = client.channels.cache.get(logChannelId);
if (!logChannel) {
console.error('Log channel not found!');
return;
}

const eventName = interaction.type === 'APPLICATION_COMMAND' ? 'interactionCreate' : interaction.eventNames[0];
let content = `Event: ${eventName}`;

// console.log(content);

logChannel.send(content)
.catch(error => console.error('Error sending log message:', error));
};

const eventNames = Object.keys(Events);

for(let i=0;i<eventNames.length;i++) {
client.on(eventNames[i],(interaction)=>{logger(interaction);});
}
const logChannelId = '1024461076689080370';

const logger = function(interaction){
const logChannel = client.channels.cache.get(logChannelId);
if (!logChannel) {
console.error('Log channel not found!');
return;
}

const eventName = interaction.type === 'APPLICATION_COMMAND' ? 'interactionCreate' : interaction.eventNames[0];
let content = `Event: ${eventName}`;

// console.log(content);

logChannel.send(content)
.catch(error => console.error('Error sending log message:', error));
};

const eventNames = Object.keys(Events);

for(let i=0;i<eventNames.length;i++) {
client.on(eventNames[i],(interaction)=>{logger(interaction);});
}
7 replies