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);