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);});
}
5 Replies
d.js toolkit
d.js toolkit7mo 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 OP
Amgelo
Amgelo7mo ago
there's no eventNames property in interaction, not sure where you got that from you could just pass the event name as a parameter in your logger to simplify things
the_1king
the_1kingOP7mo ago
Thanks! I’ll change that when I’m back at my pc later. Follow up: will this potentially create an infinite loop where an event trigger this to post in a channel which itself triggers an event?
Amgelo
Amgelo7mo ago
yes, follow what Qjuh said
the_1king
the_1kingOP7mo ago
Ah, I hadn't read his message yet. Thank you both.
Want results from more Discord servers?
Add your server