Initial commit
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
// require("../../requires")
|
||||
|
||||
module.exports = {
|
||||
name: "registerCommands",
|
||||
async function(global, guild){
|
||||
return new Promise(resolve => {
|
||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord-api-types/v9');
|
||||
|
||||
const token = config.token
|
||||
|
||||
const commandsList = []
|
||||
|
||||
|
||||
var commandstopush = "| "
|
||||
commands.forEach(element => {
|
||||
if(element.slashcommand != undefined){
|
||||
|
||||
if(global){
|
||||
if(element.slashcommandGlobal){
|
||||
commandstopush += `${element.name} | `
|
||||
commandsList.push(element.slashcommand)
|
||||
}
|
||||
}else{
|
||||
commandstopush += `${element.name} | `
|
||||
commandsList.push(element.slashcommand)
|
||||
if(element.permissions){
|
||||
commandsList[commandsList.length-1].default_member_permissions = element.permissions
|
||||
}
|
||||
}
|
||||
// commandsList.push(element.slashcommand)
|
||||
}
|
||||
});
|
||||
console.log(commandstopush);
|
||||
|
||||
const rest = new REST({ version: '9' }).setToken(token);
|
||||
|
||||
const clientId = client.user.id;
|
||||
const guildId = '929749429156724807';
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
if(!global){
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, guildId),
|
||||
{ body: commandsList },
|
||||
);
|
||||
}else{
|
||||
if(guild == undefined){
|
||||
await rest.put(
|
||||
Routes.applicationCommands(clientId),
|
||||
{ body: commandsList },
|
||||
);
|
||||
}else{
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, guild.id),
|
||||
{ body: commandsList },
|
||||
);
|
||||
}
|
||||
}
|
||||
console.log('Successfully registered application commands.');
|
||||
resolve()
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
resolve()
|
||||
}
|
||||
})();
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user