# This is a combination of 12 commits.

# This is the 1st commit message:

Initial commit
# This is the commit message #2:

added whole syswtem

becuz i forgot to keep up with the github

# This is the commit message #3:

hihi hiha

# This is the commit message #4:

added startServer.sh

# This is the commit message #5:

hihi hiha

# This is the commit message #6:

fixed some packages

# This is the commit message #7:

fixed every bug with the stupid oop

# This is the commit message #8:

Revert "fixed every bug with the stupid oop"

This reverts commit d2255863aa44e2504f9f2cec9e1ae5d1094cb9cd.

# This is the commit message #9:

added prevention of breaking the system by manually filling in the project id

# This is the commit message #10:

fixed bug when adding bot

# This is the commit message #11:

made user-id not just count up from 0

# This is the commit message #12:

fixed the issue where if you load project page it woulnt show the commands until you refresh the page
This commit is contained in:
Valentijn :)
2023-11-24 11:04:00 +01:00
committed by HerpieDerpie@example.com
commit 48a5a3576d
20 changed files with 3712 additions and 0 deletions

82
example_bot/updateCommands.js Executable file
View File

@@ -0,0 +1,82 @@
const { REST, Routes } = require('discord.js');
const { clientId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');
const generateCommandFile = (command) => {
return `const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('${command.name}')
.setDescription('${command.description}'),
async execute(interaction) {
await interaction.reply('${command.response}');
},
};
`;
};
const updateCommands = () => {
const commands = [];
const foldersPath = path.join(__dirname, 'commands');
const utilityFolderPath = path.join(foldersPath, 'utility');
// Delete all files from ./commands/utility/ before creating new ones
fs.readdirSync(utilityFolderPath).forEach((file) => {
const filePath = path.join(utilityFolderPath, file);
fs.unlinkSync(filePath);
console.log(`Deleted ${file}`);
});
// CREAYE ALL THE COMMAND FILES HERE (OVERWRITE THEM IF THEY ALREADY EXSIST)
const { commands: jsonCommands } = require('./config.json');
for (const command of jsonCommands) {
const commandFileName = `${command.name}.js`;
const commandFilePath = path.join(foldersPath, `utility/${commandFileName}`);
if (!fs.existsSync(commandFilePath)) {
// If the command file doesn't exist, create it
fs.writeFileSync(commandFilePath, generateCommandFile(command));
console.log(`Created ${commandFileName}`);
}
}
for (const folder of fs.readdirSync(foldersPath)) {
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(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
const rest = new REST().setToken(token);
(async () => {
try {
console.log(`⚙️ Started refreshing ${commands.length} application (/) commands.`);
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
console.log(`✅ Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(`${error}`);
}
})();
}
module.exports = {
updateCommands
}