Added slash command handling!
This commit is contained in:
parent
797cb48b93
commit
ba1ef05695
|
@ -3,7 +3,7 @@ const { SlashCommandBuilder } = require('discord.js');
|
|||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('ping')
|
||||
.setDescription('Replies with pong.'),
|
||||
.setDescription('This replies with pong.'),
|
||||
async execute(interaction) {
|
||||
await interaction.reply('Pong!');
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
const { REST, Routes } = require('discord.js');
|
||||
const { clientID, token } = require('./config.json');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const informationStatus = "[INFO]: ";
|
||||
const warningStatus = "[WARNING]: ";
|
||||
const errorStatus = "[ERROR]: ";
|
||||
|
||||
const commands = [];
|
||||
const foldersPath = path.join(__dirname, 'commands');
|
||||
const commandFolders = fs.readdirSync(foldersPath);
|
||||
|
||||
for (const folder of commandFolders) {
|
||||
const commandsPath = path.join(foldersPath, folder);
|
||||
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);
|
||||
if ('data' in command && 'execute' in command) {
|
||||
commands.push(command.data.toJSON());
|
||||
} else {
|
||||
console.log(warningStatus + `This file at ${filePath} does not contain data or execute properties, will be ignored.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const rest = new REST().setToken(token);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
console.log(informationStatus + `Beginning deploy commands for ${commands.length} commands!`);
|
||||
|
||||
const data = await rest.put(
|
||||
Routes.applicationCommands(clientID),
|
||||
{ body: commands },
|
||||
);
|
||||
|
||||
console.log(informationStatus + `Loaded all ${data.length} commands!`);
|
||||
} catch (error) {
|
||||
console.log(errorStatus + `Something went wrong while trying to load commanads! Refer to the error below to debug.`);
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
Loading…
Reference in a new issue