Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = {
- name: 'interactionCreate',
- async execute(interaction, client) {
- if (!interaction.isCommand()) return;
- const command = interaction.client.commands.get(interaction.commandName);
- if (!command) return;
- const settings = client.database.get('settings');
- const requiredRole = settings.requiredRole;
- const logChannelId = settings.logChannel;
- const userId = interaction.user.id;
- const userTag = interaction.user.tag;
- const commandName = interaction.commandName;
- const channelName = interaction.channel.name;
- const channelId = interaction.channel.id;
- const timestamp = new Date().toISOString();
- let status = 'Not executed';
- const logData = {
- userName: userTag,
- commandName: commandName,
- channelName: channelName,
- channelId: channelId,
- timestamp: timestamp,
- status: status,
- };
- try {
- // Check if the command is in the "admin" folder
- if (command.folder === 'admin') {
- const guildOwner = interaction.guild.ownerId;
- // Log the admin command attempt
- if (logChannelId) {
- const logChannel = await client.channels.fetch(logChannelId);
- if (logChannel) {
- const logMessage = `Admin command attempt: ${commandName} by ${userTag} in ${channelName}`;
- await logChannel.send(logMessage);
- }
- }
- // Check permissions
- if (interaction.user.id !== guildOwner && (!requiredRole || !interaction.member.roles.cache.has(requiredRole))) {
- await interaction.reply({ content: 'You do not have permission to use this command.', ephemeral: true });
- status = 'Permission denied';
- logData.status = status;
- const commandLogs = client.database.get('commandLogs');
- if (!commandLogs[userId]) {
- commandLogs[userId] = [];
- }
- commandLogs[userId].push(logData);
- client.database.set('commandLogs', commandLogs);
- return;
- }
- }
- await command.execute(interaction);
- status = 'Executed';
- } catch (error) {
- console.error(error);
- await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
- status = 'Error';
- } finally {
- // Log the command usage in the database
- logData.status = status;
- const commandLogs = client.database.get('commandLogs');
- if (!commandLogs[userId]) {
- commandLogs[userId] = [];
- }
- commandLogs[userId].push(logData);
- client.database.set('commandLogs', commandLogs);
- }
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement