Added interaction event handler
This commit is contained in:
21
events/interactions/logBtnsCmds.js
Normal file
21
events/interactions/logBtnsCmds.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: "logBtnsCmds",
|
||||||
|
description: "Logs all button and command interactions",
|
||||||
|
type: "interaction",
|
||||||
|
|
||||||
|
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */
|
||||||
|
|
||||||
|
execute(interaction) {
|
||||||
|
if (interaction.isCommand()) {
|
||||||
|
console.log(interaction.user.username + "#" +
|
||||||
|
interaction.user.discriminator + " ran " +
|
||||||
|
interaction.commandName
|
||||||
|
);
|
||||||
|
} else if (interaction.isButton()) {
|
||||||
|
console.log(interaction.user.username + "#" +
|
||||||
|
interaction.user.discriminator + " clicked " +
|
||||||
|
interaction.customId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
index.js
18
index.js
@@ -1,6 +1,5 @@
|
|||||||
const { Client, GatewayIntentBits, Partials, ActivityType, Events, Collection } = require('discord.js');
|
const { Client, GatewayIntentBits, Partials, ActivityType, Events, Collection } = require('discord.js');
|
||||||
const { botLogChannel, color } = require('./config/options.json');
|
const { loadSlashCommands, loadMessageEvents, loadContextMenu, loadModalEvents, loadButtonEvents, loadReadyEvents, loadInteractionEvents } = require('./utils/eventHandler.js')
|
||||||
const { loadSlashCommands, loadMessageEvents, loadContextMenu, loadModalEvents, loadButtonEvents, loadReadyEvents } = require('./utils/eventHandler.js')
|
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const mongoURI = process.env.MONGOURI;
|
const mongoURI = process.env.MONGOURI;
|
||||||
const { connect } = require('mongoose');
|
const { connect } = require('mongoose');
|
||||||
@@ -39,20 +38,7 @@ loadButtonEvents(client);
|
|||||||
loadModalEvents(client);
|
loadModalEvents(client);
|
||||||
loadMessageEvents(client);
|
loadMessageEvents(client);
|
||||||
loadReadyEvents(client)
|
loadReadyEvents(client)
|
||||||
|
loadInteractionEvents(client);
|
||||||
client.on(Events.InteractionCreate, async interaction => {
|
|
||||||
if (interaction.isCommand()) {
|
|
||||||
console.log(interaction.user.username + "#" +
|
|
||||||
interaction.user.discriminator + " ran " +
|
|
||||||
interaction.commandName
|
|
||||||
);
|
|
||||||
} else if (interaction.isButton()) {
|
|
||||||
console.log(interaction.user.username + "#" +
|
|
||||||
interaction.user.discriminator + " clicked " +
|
|
||||||
interaction.customId
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
client.login(token);
|
client.login(token);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ const { loadContextMenu } = require('./eventHandlers/contextmenu.js')
|
|||||||
const { loadMessageEvents } = require('./eventHandlers/message.js')
|
const { loadMessageEvents } = require('./eventHandlers/message.js')
|
||||||
const { loadModalEvents } = require('./eventHandlers/modal.js')
|
const { loadModalEvents } = require('./eventHandlers/modal.js')
|
||||||
const { loadReadyEvents } = require('./eventHandlers/ready.js')
|
const { loadReadyEvents } = require('./eventHandlers/ready.js')
|
||||||
|
const { loadInteractionEvents } = require('./eventHandlers/interaction.js')
|
||||||
|
|
||||||
|
module.exports = { loadSlashCommands, loadButtonEvents, loadContextMenu, loadMessageEvents, loadModalEvents, loadReadyEvents, loadInteractionEvents }
|
||||||
module.exports = { loadSlashCommands, loadButtonEvents, loadContextMenu, loadMessageEvents, loadModalEvents, loadReadyEvents }
|
|
||||||
|
|||||||
23
utils/eventHandlers/interaction.js
Normal file
23
utils/eventHandlers/interaction.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
const { Events } = require('discord.js')
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
/** @param { import('discord.js').Client } client */
|
||||||
|
|
||||||
|
function loadInteractionEvents(client) {
|
||||||
|
const interactionsPath = path.join(__dirname, '..', '..', 'events', 'interactions')
|
||||||
|
const interactionsFiles = fs.readdirSync(interactionsPath).filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
|
for (const file of interactionsFiles) {
|
||||||
|
const filePath = path.join(interactionsPath, file);
|
||||||
|
const interactionFile = require(filePath);
|
||||||
|
|
||||||
|
if ('name' in interactionFile && 'execute' in interactionFile && interactionFile.type === 'interaction') {
|
||||||
|
client.on(Events.InteractionCreate, interactionFile.execute)
|
||||||
|
} else {
|
||||||
|
console.log(`[WARNING] The interactions event at ${filePath} is missing a required "name", "execute" or "type" property.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { loadInteractionEvents }
|
||||||
Reference in New Issue
Block a user