Application commands not registering
For some reason my application commands haven't been registering lately.
No errors, the call to
I've tried changing the token to "a" or something equally bogus (returns 401 Unauthorized), so that is not the issue. My command objects are all valid.
Here's the script I'm using to register application commands:
Any help is appreciated.
No errors, the call to
rest.put()rest.put() just never finishes.I've tried changing the token to "a" or something equally bogus (returns 401 Unauthorized), so that is not the issue. My command objects are all valid.
Here's the script I'm using to register application commands:
import 'dotenv/config';
import {
REST,
RESTPostAPIChatInputApplicationCommandsJSONBody,
Routes,
SlashCommandBuilder
} from 'discord.js';
import { dirname, default as path } from 'path';
import { argv } from 'process';
import { clientId } from './config';
import { fileURLToPath } from 'url';
import { readdir } from 'fs/promises';
argv.shift();
argv.shift();
const thisdirname = dirname(fileURLToPath(import.meta.url));
const commands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
const commandsPath = path.join(thisdirname, 'commands');
let commandFiles;
if (argv.length == 0) {
commandFiles = (await readdir(commandsPath)).filter((file) =>
file.endsWith('.ts')
);
} else {
commandFiles = (await readdir(commandsPath)).filter(
(file) => file.endsWith('.ts') && argv.includes(file.replace('.ts', ''))
);
}
if (commandFiles.length == 0) {
console.log('No commands found');
process.exit(1);
}
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command: {
data: SlashCommandBuilder;
execute?: (interaction: unknown) => Promise<void>;
} = await import(filePath);
commands.push(command.data.toJSON());
}
if (!process.env.DISCORD_TOKEN) {
console.log('No token found');
process.exit(1);
}
console.log('Registering commands...');
const rest = new REST().setToken(process.env.DISCORD_TOKEN as string);
const data = await rest.put(Routes.applicationCommands(clientId), {
body: commands
});
console.log(data);import 'dotenv/config';
import {
REST,
RESTPostAPIChatInputApplicationCommandsJSONBody,
Routes,
SlashCommandBuilder
} from 'discord.js';
import { dirname, default as path } from 'path';
import { argv } from 'process';
import { clientId } from './config';
import { fileURLToPath } from 'url';
import { readdir } from 'fs/promises';
argv.shift();
argv.shift();
const thisdirname = dirname(fileURLToPath(import.meta.url));
const commands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
const commandsPath = path.join(thisdirname, 'commands');
let commandFiles;
if (argv.length == 0) {
commandFiles = (await readdir(commandsPath)).filter((file) =>
file.endsWith('.ts')
);
} else {
commandFiles = (await readdir(commandsPath)).filter(
(file) => file.endsWith('.ts') && argv.includes(file.replace('.ts', ''))
);
}
if (commandFiles.length == 0) {
console.log('No commands found');
process.exit(1);
}
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command: {
data: SlashCommandBuilder;
execute?: (interaction: unknown) => Promise<void>;
} = await import(filePath);
commands.push(command.data.toJSON());
}
if (!process.env.DISCORD_TOKEN) {
console.log('No token found');
process.exit(1);
}
console.log('Registering commands...');
const rest = new REST().setToken(process.env.DISCORD_TOKEN as string);
const data = await rest.put(Routes.applicationCommands(clientId), {
body: commands
});
console.log(data);Any help is appreciated.