CoolFace
Apppublic

pythonsnake/counting-bot

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
deploy-commands.js47 linesDownload Raw Back to root
1const { REST, Routes } = require('discord.js');2 3const token = process.env["DISCORD_TOKEN"];4const clientId = process.env["DISCORD_CLIENT_ID"];5 6const fs = require('node:fs');7const path = require('node:path');8 9const commands = [];10// Grab all the command files from the commands directory you created earlier11const commandsPath = path.join(__dirname, 'commands');12const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));13 14for (const file of commandFiles) {15	const filePath = path.join(commandsPath, file);16	const command = require(filePath);17	// Set a new item in the Collection with the key as the command name and the value as the exported module18	if ('data' in command && 'execute' in command) {19		commands.push(command.data.toJSON());20	} else {21		console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);22	}23}24 25console.log(clientId);26 27// Construct and prepare an instance of the REST module28const rest = new REST().setToken(token);29 30// and deploy your commands!31(async () => {32	try {33		console.log(`Started refreshing ${commands.length} application (/) commands.`);34 35		// The put method is used to fully refresh all commands in the guild with the current set36		const data = await rest.put(37			Routes.applicationCommands(clientId),38			{ body: commands },39		);40 41		console.log(`Successfully reloaded ${data.length} application (/) commands.`);42	} catch (error) {43		// And of course, make sure you catch and log any errors!44		console.error(error);45	}46})();47