43 lines
1.8 KiB
JavaScript
43 lines
1.8 KiB
JavaScript
const { SlashCommandBuilder, PermissionFlagsBits, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
|
const { readDb } = require('../../backend/db');
|
|
|
|
module.exports = {
|
|
name: 'list-invites',
|
|
description: 'List invites created by the bot for this guild',
|
|
enabled: true,
|
|
builder: new SlashCommandBuilder()
|
|
.setName('list-invites')
|
|
.setDescription('List invites created by the bot for this guild')
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
|
async execute(interaction) {
|
|
try {
|
|
const db = readDb();
|
|
const invites = (db[interaction.guildId] && db[interaction.guildId].invites) ? db[interaction.guildId].invites : [];
|
|
|
|
if (!invites.length) {
|
|
await interaction.reply({ content: 'No invites created by the bot in this server.', ephemeral: true });
|
|
return;
|
|
}
|
|
|
|
// Build a message with invite details and action buttons
|
|
for (const inv of invites) {
|
|
const created = inv.createdAt || 'Unknown';
|
|
const uses = inv.uses || inv.maxUses || 0;
|
|
const temporary = inv.temporary ? 'Yes' : 'No';
|
|
const content = `Invite: ${inv.url}\nCreated: ${created}\nUses: ${uses}\nMax Uses: ${inv.maxUses || 0}\nMax Age (s): ${inv.maxAge || 0}\nTemporary: ${temporary}`;
|
|
|
|
const row = new ActionRowBuilder()
|
|
.addComponents(
|
|
new ButtonBuilder().setLabel('Copy Invite').setStyle(ButtonStyle.Secondary).setCustomId(`copy_inv_${inv.code}`),
|
|
new ButtonBuilder().setLabel('Delete Invite').setStyle(ButtonStyle.Danger).setCustomId(`delete_inv_${inv.code}`),
|
|
);
|
|
|
|
await interaction.reply({ content, components: [row], ephemeral: true });
|
|
}
|
|
} catch (error) {
|
|
console.error('Error in list-invites:', error);
|
|
await interaction.reply({ content: 'Failed to list invites.', ephemeral: true });
|
|
}
|
|
},
|
|
};
|