You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
// new
|
|
// In order to get your application's client id, go to Discord Developer Portal and choose your application. Find the id under "Application ID" in General Information subpage. To get guild id, open Discord and go to your settings. On the "Advanced" page, turn on "Developer Mode". This will enable a "Copy ID" button in the context menu when you right-click on a server icon, a user's profile, etc.
|
|
|
|
//node deploy-commands.js when adding/editing commands
|
|
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
|
const { REST } = require('@discordjs/rest');
|
|
const { Routes } = require('discord-api-types/v9');
|
|
const config = require('./config.json');
|
|
|
|
|
|
const commands = [];
|
|
const commandsPath = path.join(__dirname, 'commands');
|
|
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
|
|
|
for (const file of commandFiles) {
|
|
const filePath = path.join(commandsPath, file);
|
|
const command = require(filePath);
|
|
commands.push(command.data.toJSON());
|
|
}
|
|
|
|
//const commands = [
|
|
//new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!'),
|
|
//new SlashCommandBuilder().setName('server').setDescription('Replies with server info!'),
|
|
//new SlashCommandBuilder().setName('user').setDescription('Replies with user info!'),
|
|
//]
|
|
//.map(command => command.toJSON());
|
|
|
|
const rest = new REST({ version: '9' }).setToken(config.token);
|
|
|
|
rest.put(Routes.applicationGuildCommands(config.clientId, config.guildId), { body: commands })
|
|
.then(() => console.log('Successfully registered application commands.'))
|
|
.catch(console.error);
|
|
|