convert some commands to global commands

This commit is contained in:
SowinskiBraeden committed 2022-08-30 11:52:36 -07:00
1 parent 8330ece067
commit 7c8c484122
19 files changed
+72 -24

No files matched your search

+51 -21
View File
@@ -6,34 +6,64 @@ const { REST } = require('@discordjs/rest');
/**
* Register slash commands for a guild
* @param {require("../structures/QuarksBot")} client
* @param {string} guild
*/
module.exports = async function(client, guild) {
module.exports = {
// Register guild commands
RegisterGuildCommands: async function(client, guild) {
const commands = [];
const commandFiles = fs.readdirSync(path.join(__dirname, "..", "commands")).filter(file => file.endsWith('.js'));
const commands = [];
const commandFiles = fs.readdirSync(path.join(__dirname, "..", "commands")).filter(file => file.endsWith('.js'));
// Place your client and guild ids here
const clientId = client.application.id;
const guildId = guild;
// Place your client and guild ids here
const clientId = client.application.id;
const guildId = guild;
for (const file of commandFiles) {
const command = require(`../commands/${file}`);
if (!command.global) commands.push(command);
}
for (const file of commandFiles) {
const command = require(`../commands/${file}`);
commands.push(command);
}
const rest = new REST({ version: '10' }).setToken(client.config.Token);
const rest = new REST({ version: '10' }).setToken(client.config.Token);
try {
client.log(`[${guildId}] Started refreshing guild (/) commands.`);
try {
client.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
client.log(`[${guildId}] Successfully reloaded guild (/) commands.`);
} catch (error) {
client.error(error);
}
},
client.log('Successfully reloaded application (/) commands.');
} catch (error) {
client.error(error);
// Register global commands
RegisterGlobalCommands: async function(client) {
const commands = [];
const commandFiles = fs.readdirSync(path.join(__dirname, "..", "commands")).filter(file => file.endsWith('.js'));
// Place your client and guild ids here
const clientId = client.application.id;
for (const file of commandFiles) {
const command = require(`../commands/${file}`);
if (command.global) commands.push(command);
}
const rest = new REST({ version: '10' }).setToken(client.config.Token);
try {
client.log('[global] Started refreshing global (/) commands.');
await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);
client.log('[global] Successfully reloaded global (/) commands.');
} catch (error) {
client.error(error);
}
}
};