Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

DISCORD JS SLASH COMMAND

const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { token } = require('./config.json');
const fs = require('node:fs');

const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

// Place your client and guild ids here
const clientId = '123456789012345678';
const guildId = '876543210987654321';

for (const file of commandFiles) {
	const command = require(`./commands/${file}`);
	commands.push(command.data.toJSON());
}

const rest = new REST({ version: '9' }).setToken(token);

(async () => {
	try {
		console.log('Started refreshing application (/) commands.');

		await rest.put(
			Routes.applicationGuildCommands(clientId, guildId),
			{ body: commands },
		);

		console.log('Successfully reloaded application (/) commands.');
	} catch (error) {
		console.error(error);
	}
})();
Comment

PREVIOUS NEXT
Code Example
Javascript :: dispatch on unmount 
Javascript :: import NativeMethodsMixin from "NativeMethodsMixin"; error 
Javascript :: event pooling in react/event.persist/using async function in event callback 
Javascript :: check if array in conditional chaining javascript 
Javascript :: js rgba to hex 
Javascript :: react conditional arrow map array 
Javascript :: 8.1.1. Declaring an Array¶ 
Javascript :: runincontext execute function 
Javascript :: 9.4.1.3. Update Expression¶ // Loops 
Javascript :: broadcast channel mdn 
Javascript :: json-parsejson-stringifyx-purpose 
Javascript :: express js jump to above directory 
Javascript :: AngularJS module can be created using ............ A. module.create(); B.angular.create(); C.angular.module(); D.var myModule = new module(); 
Javascript :: %20find%20all%20docs%20that%20have%20at%20least%20two%20name%20array%20elements_ 
Javascript :: jquery ui sortable disable child 
Javascript :: remove 0 from 01 
Javascript :: await fetch data componentdidmount 
Javascript :: best way to store db config in node js 
Javascript :: window.getselection outside 
Javascript :: array object sort by date 
Javascript :: how to make password star star on input html 
Javascript :: setting part of times in javascript 
Javascript :: map for id 
Javascript :: ejs toggle class 
Javascript :: react application preloader add 
Javascript :: how to get all key values of Json 
Javascript :: jquery keyup only alphanumeric 
Javascript :: scale sprite matter.js 
Javascript :: calling computed function inside methods 
Javascript :: when reload the page the route gone in react js laravel 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =