Update command registration to preserve existing entry points
Modify the command registration script to fetch and preserve existing entry point commands while registering new ones, using environment variables for DISCORD_BOT_TOKEN and DISCORD_CLIENT_ID. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e72fc1b7-94bd-4d6c-801f-cbac2fae245c Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 713e3b6c-1c1e-474c-8cab-f254e83be29b Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/e72fc1b7-94bd-4d6c-801f-cbac2fae245c/MSxeu36 Replit-Helium-Checkpoint-Created: true
This commit is contained in:
parent
d0bc5a982f
commit
42c2ba799f
1 changed files with 29 additions and 4 deletions
|
|
@ -110,19 +110,44 @@ const commands = [
|
|||
},
|
||||
];
|
||||
|
||||
const token = process.env.DISCORD_BOT_TOKEN || process.env.DISCORD_TOKEN;
|
||||
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 rest = new REST({ version: '10' }).setToken(token);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
console.log('Registering slash commands...');
|
||||
console.log('Fetching 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];
|
||||
|
||||
console.log(`Registering ${commands.length} commands (preserving ${entryPointCommands.length} entry points)...`);
|
||||
|
||||
const data = await rest.put(
|
||||
Routes.applicationCommands(process.env.DISCORD_CLIENT_ID),
|
||||
{ body: commands }
|
||||
Routes.applicationCommands(clientId),
|
||||
{ body: allCommands }
|
||||
);
|
||||
|
||||
console.log(`Successfully registered ${data.length} commands`);
|
||||
data.forEach(cmd => console.log(` - /${cmd.name}`));
|
||||
} catch (error) {
|
||||
console.error('Error registering commands:', error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue