there is problem registrign slashcpmamnds
its stuck like this

9 Replies
my registercomamnd file
its been working perfectly
i did use the command much
but not 200
smth near 60-70
import 'dotenv/config';
import { REST, Routes } from 'discord.js';
import { readdirSync } from 'fs';
import { join } from 'path';
import logger from './logger';
import { BaseCommand } from './../base/Command';
async function getCommands(): Promise<any[]> {
const commands: any[] = [];
const commandsPath = join(__dirname, '..', 'commands');
try {
const categories = readdirSync(commandsPath, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
for (const category of categories) {
const categoryPath = join(commandsPath, category);
const commandFiles = readdirSync(categoryPath)
.filter(file => file.endsWith('.ts') || file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = join(categoryPath, file);
try {
const commandModule = await import(filePath);
const CommandClass = Object.values(commandModule).find(
(exp): exp is new () => BaseCommand =>
typeof exp === 'function' &&
exp.prototype instanceof BaseCommand
);
if (CommandClass) {
const command = new CommandClass();
commands.push(command.data.toJSON());
logger.info(`Registered command: ${command.options.name}`);
}
} catch (error) {
logger.error(`Error loading command from ${file}:`, error);
}
}
}
} catch (error) {
logger.error('Error loading command categories:', error);
}
return commands;
}
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN!);
async function registerCommands(): Promise<void> {
try {
const commands = await getCommands();
if (!process.env.CLIENT_ID) {
throw new Error('CLIENT_ID is not set in environment variables');
}
if (!process.env.GUILD_ID) {
logger.info('GUILD_ID not set, registering commands globally (this can take up to 1 hour)');
await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands }
);
} else {
logger.info('Registering commands for specific guild');
await rest.put(
Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.GUILD_ID),
{ body: commands }
);
}
logger.info(`Successfully registered ${commands.length} commands.`);
} catch (error) {
logger.error('Error registering commands:', error);
process.exit(1);
}
}
if (require.main === module) {
registerCommands();
}
export { registerCommands };
import 'dotenv/config';
import { REST, Routes } from 'discord.js';
import { readdirSync } from 'fs';
import { join } from 'path';
import logger from './logger';
import { BaseCommand } from './../base/Command';
async function getCommands(): Promise<any[]> {
const commands: any[] = [];
const commandsPath = join(__dirname, '..', 'commands');
try {
const categories = readdirSync(commandsPath, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
for (const category of categories) {
const categoryPath = join(commandsPath, category);
const commandFiles = readdirSync(categoryPath)
.filter(file => file.endsWith('.ts') || file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = join(categoryPath, file);
try {
const commandModule = await import(filePath);
const CommandClass = Object.values(commandModule).find(
(exp): exp is new () => BaseCommand =>
typeof exp === 'function' &&
exp.prototype instanceof BaseCommand
);
if (CommandClass) {
const command = new CommandClass();
commands.push(command.data.toJSON());
logger.info(`Registered command: ${command.options.name}`);
}
} catch (error) {
logger.error(`Error loading command from ${file}:`, error);
}
}
}
} catch (error) {
logger.error('Error loading command categories:', error);
}
return commands;
}
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN!);
async function registerCommands(): Promise<void> {
try {
const commands = await getCommands();
if (!process.env.CLIENT_ID) {
throw new Error('CLIENT_ID is not set in environment variables');
}
if (!process.env.GUILD_ID) {
logger.info('GUILD_ID not set, registering commands globally (this can take up to 1 hour)');
await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands }
);
} else {
logger.info('Registering commands for specific guild');
await rest.put(
Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.GUILD_ID),
{ body: commands }
);
}
logger.info(`Successfully registered ${commands.length} commands.`);
} catch (error) {
logger.error('Error registering commands:', error);
process.exit(1);
}
}
if (require.main === module) {
registerCommands();
}
export { registerCommands };
(this can take up to 1 hour)this isn't a thing btw
oh :-
tkniuu
just to confirm, put
rest.on('rateLimited', console.log) right below your const rest = ...
yeah you're ratelimited then
for how long
24hrs?
oh okk gotcha
thank you
for ur help
appreciate it
The thread owner has marked this issue as solved.