diff --git a/src/commands/checkperms.ts b/src/commands/checkperms.ts index 0136870..bd1b0a2 100644 --- a/src/commands/checkperms.ts +++ b/src/commands/checkperms.ts @@ -5,6 +5,7 @@ import { import { getMemberPermissionsRaw } from '../db' module.exports = { + global: false, data: new SlashCommandBuilder() .setName('checkperms') .addUserOption((option) => diff --git a/src/commands/checkroles.ts b/src/commands/checkroles.ts index 0076ee3..47d5bd9 100644 --- a/src/commands/checkroles.ts +++ b/src/commands/checkroles.ts @@ -5,6 +5,7 @@ import { import { execute, type PermsNumbers } from '../db' module.exports = { + global: false, data: new SlashCommandBuilder() .setName('checkroles') .setDescription('Prints all roles in the database'), diff --git a/src/commands/delrole.ts b/src/commands/delrole.ts index ed66d29..ee72663 100644 --- a/src/commands/delrole.ts +++ b/src/commands/delrole.ts @@ -6,6 +6,7 @@ import { import { execute } from '../db' module.exports = { + global: false, data: new SlashCommandBuilder() .setName('delrole') .setDescription('Delete a role from the database') diff --git a/src/commands/forceload.ts b/src/commands/forceload.ts index 98de50b..29fca0f 100644 --- a/src/commands/forceload.ts +++ b/src/commands/forceload.ts @@ -7,6 +7,7 @@ import { execute, insertGoob } from '../db' import { owner_id } from '../config.json' module.exports = { + global: false, data: new SlashCommandBuilder() .setName('forceload') .setDescription('Add a message in and its attachements to the database') diff --git a/src/commands/goob.ts b/src/commands/goob.ts index dd902c6..1ab4c4f 100644 --- a/src/commands/goob.ts +++ b/src/commands/goob.ts @@ -5,6 +5,7 @@ import { import { checkMemberPermissions, deleteGoob, execute } from '../db' module.exports = { + global: true, data: new SlashCommandBuilder() .setName('goob') .setDescription('meow').addIntegerOption(option => diff --git a/src/commands/load.ts b/src/commands/load.ts index 34920b1..0a162f3 100644 --- a/src/commands/load.ts +++ b/src/commands/load.ts @@ -8,6 +8,7 @@ import { owner_id } from '../config.json' import db, { checkMemberPermissions, execute, insertGoob } from '../db' module.exports = { + global: false, data: new SlashCommandBuilder() .setName('load') .setDescription('Loads all past goobers from this channel'), diff --git a/src/commands/setrole.ts b/src/commands/setrole.ts index 5cc0362..37a9f72 100644 --- a/src/commands/setrole.ts +++ b/src/commands/setrole.ts @@ -3,8 +3,10 @@ import { SlashCommandBuilder, PermissionsBitField } from 'discord.js' import { execute } from '../db' +import { discord_guild_id } from '../config.json' module.exports = { + global: false, data: new SlashCommandBuilder() .setName('setrole') .setDescription('Adds permissions to a discord role') @@ -37,6 +39,10 @@ module.exports = { void interaction.reply({ content: 'Cannot find role', ephemeral: true }) return } + if (interaction.guildId !== discord_guild_id) { + void interaction.reply({ content: 'I am sorry dave, I\'m afraid I cannot do that\nRole settings are only available in main guild', ephemeral: true }) + return + } if ((interaction.memberPermissions?.has(PermissionsBitField.Flags.ManageRoles, true)) !== true) { void interaction.reply({ content: 'I am sorry dave, I\'m afraid I cannot do that\nYou don\'t have the permission to manage roles on this server', ephemeral: true }) return diff --git a/src/commands/sync.ts b/src/commands/sync.ts index 1fc1de0..8324ead 100644 --- a/src/commands/sync.ts +++ b/src/commands/sync.ts @@ -7,6 +7,7 @@ import { owner_id } from '../config.json' import db, { execute } from '../db' module.exports = { + global: false, data: new SlashCommandBuilder() .setName('sync') .setDescription('Synchronise all past and future goobers from this channel'), diff --git a/src/db/index.ts b/src/db/index.ts index 7e87f28..f6688ae 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -34,7 +34,7 @@ export async function getMemberPermissionsRaw (member: GuildMember): Promise file.endsWith('.js')) + +const promises = [] as Array> +for (const file of commandFiles) { + const filePath = path.join(commandsPath, file) + promises.push(import(filePath).then(({ default: command, global }) => { + if (global === true) return + if ('data' in command && 'execute' in command) { + commands.push(command.data.toJSON()) + } else { + console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`) + } + })) + // Set a new item in the Collection with the key as the command name and the value as the exported module +} + +// Construct and prepare an instance of the REST module +const rest = new REST().setToken(discord_token) + +// and deploy your commands! + +void Promise.all(promises).then(async () => { + try { + console.log(`Started refreshing ${commands.length} application (/) commands.`) + + // The put method is used to fully refresh all commands in the guild with the current set + const data = await rest.put( + Routes.applicationCommands(discord_app_id), + { body: commands } + + ) + + console.log(`Successfully reloaded ${(data as string[]).length} application (/) commands.`) + } catch (error) { + // And of course, make sure you catch and log any errors! + console.error(error) + } +})