diff --git a/commands/311.js b/commands/311.js index 082f779..5545b8e 100644 --- a/commands/311.js +++ b/commands/311.js @@ -3,6 +3,7 @@ const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require(' module.exports = { name: "311", debug: false, + global: false, description: "Report a non emergency", usage: "[name] [service] [location] [nature]", permissions: { diff --git a/commands/911.js b/commands/911.js index 1878ead..5abce38 100644 --- a/commands/911.js +++ b/commands/911.js @@ -3,6 +3,7 @@ const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require(' module.exports = { name: "911", debug: false, + global: false, description: "Call the emergency hotline", usage: "[name] [service] [location] [nature]", permissions: { diff --git a/commands/bank.js b/commands/bank.js index 4fc1600..c776be6 100644 --- a/commands/bank.js +++ b/commands/bank.js @@ -5,6 +5,7 @@ const { Inventory, addInventory } = require('../structures/inventory'); module.exports = { name: "bank", debug: false, + global: false, description: "Manage your banking", usage: "[cmd] [opt], flags: (1 << 6)", permissions: { diff --git a/commands/fine.js b/commands/fine.js index 97026fb..a3b1966 100644 --- a/commands/fine.js +++ b/commands/fine.js @@ -4,6 +4,7 @@ const { Bank, addBank } = require('../structures/bank'); module.exports = { name: "fine", debug: false, + global: false, description: "Fine a user for an offense", usage: "[user] [amount]", permissions: { diff --git a/commands/help.js b/commands/help.js index 64a84d4..f8d3d44 100644 --- a/commands/help.js +++ b/commands/help.js @@ -4,6 +4,7 @@ const settings = require('../config/settingsHelp'); module.exports = { name: "help", debug: false, + global: true, description: "Get information on a specific command", usage: "[option]", permissions: { diff --git a/commands/inventory.js b/commands/inventory.js index 27a3a53..ec7e222 100644 --- a/commands/inventory.js +++ b/commands/inventory.js @@ -6,6 +6,7 @@ const getActions = ['pick up', 'grab', 'get', 'aquire', 'obtain', 'gain', 'take module.exports = { name: "inventory", debug: false, + global: false, description: "Manage your inventory", usage: "[command]", permissions: { diff --git a/commands/me.js b/commands/me.js index 1fad84f..b78760f 100644 --- a/commands/me.js +++ b/commands/me.js @@ -3,6 +3,7 @@ const { EmbedBuilder } = require('discord.js'); module.exports = { name: "me", debug: false, + global: false, description: "Send a message stating your characters action", usage: "[action]", permissions: { diff --git a/commands/money.js b/commands/money.js index d201a6b..2269594 100644 --- a/commands/money.js +++ b/commands/money.js @@ -4,6 +4,7 @@ const { Bank, addBank } = require('../structures/bank'); module.exports = { name: "money", debug: false, + global: false, description: "add/remove money from user", usage: "[opt.] [user] [amount]", permissions: { diff --git a/commands/ping.js b/commands/ping.js index 04d06eb..ffa1d81 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -3,6 +3,7 @@ const { EmbedBuilder } = require('discord.js'); module.exports = { name: "ping", debug: true, + global: true, description: "Test bot activity", usage: "", permissions: { diff --git a/commands/reset.js b/commands/reset.js index 106f5e1..e53eaed 100644 --- a/commands/reset.js +++ b/commands/reset.js @@ -5,6 +5,7 @@ const { addBank } = require('../structures/bank'); module.exports = { name: "reset", debug: false, + global: false, description: "Reset a users data", usage: "[user]", permissions: { diff --git a/commands/search.js b/commands/search.js index 204515d..93bc837 100644 --- a/commands/search.js +++ b/commands/search.js @@ -4,6 +4,7 @@ const { Inventory, addInventory } = require('../structures/inventory'); module.exports = { name: "search", debug: false, + global: false, description: "Search a users inventory", usage: "[user]", permissions: { diff --git a/commands/settings.js b/commands/settings.js index 2f5eb99..b6ca882 100644 --- a/commands/settings.js +++ b/commands/settings.js @@ -4,6 +4,7 @@ const bitfieldCalculator = require('discord-bitfield-calculator'); module.exports = { name: "settings", debug: false, + global: false, description: "Configure your server settings", usage: "[opt] [action] [value]", permissions: { diff --git a/commands/stats.js b/commands/stats.js index 3a89b3e..427c62f 100644 --- a/commands/stats.js +++ b/commands/stats.js @@ -3,6 +3,7 @@ const { EmbedBuilder } = require('discord.js'); module.exports = { name: "stats", debug: true, + global: true, description: "check bot statistics", usage: "", permissions: { diff --git a/commands/tweet.js b/commands/tweet.js index 58c2fb7..349d765 100644 --- a/commands/tweet.js +++ b/commands/tweet.js @@ -3,6 +3,7 @@ const { EmbedBuilder } = require('discord.js'); module.exports = { name: "tweet", debug: false, + global: false, description: "Tweet your thoughts to the local twitter page", usage: "[message]", permissions: { diff --git a/commands/wallet.js b/commands/wallet.js index 21aee37..80274d5 100644 --- a/commands/wallet.js +++ b/commands/wallet.js @@ -3,6 +3,7 @@ const { EmbedBuilder } = require('discord.js'); module.exports = { name: "wallet", debug: false, + global: false, description: "manage your wallet", usage: "[cmd] [opt]", permissions: { diff --git a/commands/work-roles.js b/commands/work-roles.js index 0952dc6..5985052 100644 --- a/commands/work-roles.js +++ b/commands/work-roles.js @@ -3,6 +3,7 @@ const { EmbedBuilder } = require('discord.js'); module.exports = { name: "work-roles", debug: false, + global: false, description: "list work roles", usage: "", permissions: { diff --git a/commands/work.js b/commands/work.js index 55188a4..b336b1e 100644 --- a/commands/work.js +++ b/commands/work.js @@ -5,6 +5,7 @@ const { Bank, addBank } = require('../structures/bank'); module.exports = { name: "work", debug: false, + global: false, description: "work to earn your income", usage: "", permissions: { diff --git a/structures/QuarksBot.js b/structures/QuarksBot.js index 609fa58..e59c431 100644 --- a/structures/QuarksBot.js +++ b/structures/QuarksBot.js @@ -1,3 +1,4 @@ +const { RegisterGlobalCommands, RegisterGuildCommands} = require("../util/RegisterSlashCommands"); const { Collection, Client, EmbedBuilder, Routes } = require('discord.js'); const MongoClient = require('mongodb').MongoClient; const { REST } = require('@discordjs/rest'); @@ -132,10 +133,10 @@ class QuarksBot extends Client { Channel.send(embed); } + // Calls register for guild and global commands RegisterSlashCommands() { - this.guilds.cache.forEach((guild) => { - require("../util/RegisterSlashCommands")(this, guild.id); - }); + RegisterGlobalCommands(this); + this.guilds.cache.forEach((guild) => {RegisterGuildCommands(this, guild.id)}); } async GetGuild(GuildId) { diff --git a/util/RegisterSlashCommands.js b/util/RegisterSlashCommands.js index 0d4acfd..41ae715 100644 --- a/util/RegisterSlashCommands.js +++ b/util/RegisterSlashCommands.js @@ -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); + } } }; \ No newline at end of file