Removes username from Discord verification storage and updates command registration in `register-commands.js` by reading commands from files. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e72fc1b7-94bd-4d6c-801f-cbac2fae245c Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 8cea5b2a-c220-46e6-ae1b-2d0b4f9e52e4 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/e72fc1b7-94bd-4d6c-801f-cbac2fae245c/NXjYRWJ Replit-Helium-Checkpoint-Created: true
89 lines
2.6 KiB
JavaScript
89 lines
2.6 KiB
JavaScript
const { REST, Routes } = require('discord.js');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
require('dotenv').config();
|
|
|
|
const token = process.env.DISCORD_BOT_TOKEN;
|
|
const clientId = process.env.DISCORD_CLIENT_ID;
|
|
|
|
if (!token) {
|
|
console.error('Missing DISCORD_BOT_TOKEN');
|
|
process.exit(1);
|
|
}
|
|
|
|
if (!clientId) {
|
|
console.error('Missing DISCORD_CLIENT_ID');
|
|
process.exit(1);
|
|
}
|
|
|
|
const commandsPath = path.join(__dirname, '../commands');
|
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
|
|
|
const commands = [];
|
|
|
|
for (const file of commandFiles) {
|
|
const filePath = path.join(commandsPath, file);
|
|
const command = require(filePath);
|
|
if ('data' in command && 'execute' in command) {
|
|
commands.push(command.data.toJSON());
|
|
console.log(`Loaded command: ${command.data.name}`);
|
|
}
|
|
}
|
|
|
|
const rest = new REST({ version: '10' }).setToken(token);
|
|
|
|
(async () => {
|
|
try {
|
|
console.log(`\nFetching existing commands...`);
|
|
|
|
const existingCommands = await rest.get(
|
|
Routes.applicationCommands(clientId)
|
|
);
|
|
|
|
console.log(`Found ${existingCommands.length} existing commands`);
|
|
|
|
const entryPointCommands = existingCommands.filter(cmd => cmd.type === 4);
|
|
|
|
const allCommands = [...commands, ...entryPointCommands.map(cmd => ({
|
|
name: cmd.name,
|
|
description: cmd.description,
|
|
type: cmd.type,
|
|
handler: cmd.handler,
|
|
}))];
|
|
|
|
console.log(`Registering ${commands.length} commands (preserving ${entryPointCommands.length} entry points)...`);
|
|
|
|
const data = await rest.put(
|
|
Routes.applicationCommands(clientId),
|
|
{ body: allCommands }
|
|
);
|
|
|
|
console.log(`\nSuccessfully registered ${data.length} commands:`);
|
|
data.forEach(cmd => console.log(` - /${cmd.name}`));
|
|
} catch (error) {
|
|
if (error.code === 50240) {
|
|
console.warn('\nEntry Point detected. Registering individually...');
|
|
|
|
let successCount = 0;
|
|
for (const command of commands) {
|
|
try {
|
|
await rest.post(
|
|
Routes.applicationCommands(clientId),
|
|
{ body: command }
|
|
);
|
|
console.log(` + /${command.name}`);
|
|
successCount++;
|
|
} catch (postError) {
|
|
if (postError.code === 50045) {
|
|
console.log(` ~ /${command.name} (already exists)`);
|
|
} else {
|
|
console.error(` x /${command.name}: ${postError.message}`);
|
|
}
|
|
}
|
|
}
|
|
console.log(`\nRegistered ${successCount} commands individually.`);
|
|
} else {
|
|
console.error('Error registering commands:', error);
|
|
}
|
|
}
|
|
})();
|