Application commands not registering

For some reason my application commands haven't been registering lately. No errors, the call to 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.
4 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
[object Object]
[object Object]10mo ago
discord.js@14.13.0 node v20.5.1
Toast
Toast10mo ago
are your command files in JS or just TS? also idk if RESTPostAPIChatInputApplicationCommandsJSONBody[] is really needed in commands variable.
[object Object]
[object Object]9mo ago
They are all written in TypeScript, my whole bot is. You're right, it's not. Once upon a time TypeScript was complaining so I explicitly typed it at declaration. Nope. Even on the first try for the day nothing happens Doesn't matter when the timeframe starts I've tried once every 24h Believe me, it's not that The commands are not located if I use the .js extension in my code I'm using tsc... just to type-check. I use tsx to run TypeScript files without transpiling with tsc. That's why I need the *.ts extension. Must have been some problem with Discord's backend. I deleted my current application, created a new one, updated the ID and token... and all commands registered in just 5 seconds.