fixed themes and ui added new features
This commit is contained in:
54
discord-bot/commands/create-invite.js
Normal file
54
discord-bot/commands/create-invite.js
Normal file
@@ -0,0 +1,54 @@
|
||||
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
|
||||
const { readDb, writeDb } = require('../../backend/db');
|
||||
|
||||
module.exports = {
|
||||
name: 'create-invite',
|
||||
description: 'Create a Discord invite with options (channel optional, maxAge seconds, maxUses, temporary).',
|
||||
enabled: true,
|
||||
builder: new SlashCommandBuilder()
|
||||
.setName('create-invite')
|
||||
.setDescription('Create a Discord invite with options (channel optional, maxAge seconds, maxUses, temporary).')
|
||||
.addChannelOption(opt => opt.setName('channel').setDescription('Channel to create invite in').setRequired(false))
|
||||
.addIntegerOption(opt => opt.setName('maxage').setDescription('Duration in seconds (0 means never expire)').setRequired(false))
|
||||
.addIntegerOption(opt => opt.setName('maxuses').setDescription('Number of uses allowed (0 means unlimited)').setRequired(false))
|
||||
.addBooleanOption(opt => opt.setName('temporary').setDescription('Temporary membership?').setRequired(false))
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
|
||||
async execute(interaction) {
|
||||
try {
|
||||
const channel = interaction.options.getChannel('channel');
|
||||
const maxAge = interaction.options.getInteger('maxage') || 0;
|
||||
const maxUses = interaction.options.getInteger('maxuses') || 0;
|
||||
const temporary = interaction.options.getBoolean('temporary') || false;
|
||||
|
||||
const targetChannel = channel || interaction.guild.channels.cache.find(c => c.type === 0);
|
||||
if (!targetChannel) {
|
||||
await interaction.reply({ content: 'No valid channel found to create an invite.', ephemeral: true });
|
||||
return;
|
||||
}
|
||||
|
||||
const invite = await targetChannel.createInvite({ maxAge, maxUses, temporary, unique: true });
|
||||
|
||||
const db = readDb();
|
||||
if (!db[interaction.guildId]) db[interaction.guildId] = {};
|
||||
if (!db[interaction.guildId].invites) db[interaction.guildId].invites = [];
|
||||
|
||||
const item = {
|
||||
code: invite.code,
|
||||
url: invite.url,
|
||||
channelId: targetChannel.id,
|
||||
createdAt: new Date().toISOString(),
|
||||
maxUses: invite.maxUses || maxUses || 0,
|
||||
maxAge: invite.maxAge || maxAge || 0,
|
||||
temporary: !!invite.temporary,
|
||||
};
|
||||
|
||||
db[interaction.guildId].invites.push(item);
|
||||
writeDb(db);
|
||||
|
||||
await interaction.reply({ content: `Invite created: ${invite.url}`, ephemeral: true });
|
||||
} catch (error) {
|
||||
console.error('Error in create-invite:', error);
|
||||
await interaction.reply({ content: 'Failed to create invite.', ephemeral: true });
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user