#Global and Local

1 messages · Page 1 of 1 (latest)

knotty mango
#

ok so

knotty quartz
#

hello

quasi scarab
#

eval guild.commands possibly with a map or something to see what all is contained in it

knotty mango
#

I am still trying to update to discord v14 from v13.2, so I just basically reprogrammed my whole entire bot, doing this, I used the discordjs.guide and got the deploy-commands.js

quasi scarab
#

possibly cache

knotty mango
#
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');

const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
    // Grab all the command files from the commands directory you created earlier
    const commandsPath = path.join(foldersPath, folder);
    const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
    // Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
    for (const file of commandFiles) {
        const filePath = path.join(commandsPath, file);
        const command = require(filePath);
        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.`);
        }
    }
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);

// and deploy your commands!
(async () => {
    try {

        // The put method is used to fully refresh all commands in the guild with the current set
        const data = await rest.put(
            Routes.applicationCommands(clientId),
            { body: commands },
        );

        console.log(`Successfully reloaded ${data.length} application (/) commands.`);
    } catch (error) {
        // And of course, make sure you catch and log any errors!
        console.error(error);
    }
})();
#

This is where the script comes in

#

I do realise that I changed it to
Routes.applicationCommands(clientId),
instead of the guildCommands or w/e

quasi scarab
#

did you ever delete the guild-deployed commands

knotty mango
#

To my knowledge, yes
But there is a chance that I have done it incorrectly

knotty quartz
#

before we even get to it, do you have duplicate commands?

knotty mango
#

I do not have duplicate commands

quasi scarab
#

yes, they showed a ss earlier

knotty quartz
#

just confirming the issue

knotty mango
#

ping is only shown once

#

But the thing that makes me super confused

quasi scarab
#

not in your files, in discord client

knotty quartz
#

when you type /ping, do multiple commands come up?

quasi scarab
quick shellBOT
knotty mango
#

Is that it is only for older commands, newer commands only have one shown (as it should)

quasi scarab
#

check this collection

knotty quartz
#

are commands cached now? i used to know they had to be fetched

quasi scarab
#

there's a cache for them, i dunno if it's populated on ready or needs to be fetched

#

i've also never made a slash command mmLol

knotty mango
#

Forgive me since I am still trying to learn discord v14 peepoSad
But I'm not sure how to properly check for these "cached" commands

#

I

#

DO NOT LIKE SLASH COMMANDS LUL

#

They're amazing and cool and efficient

#

But programming them, I hate it LUL

quasi scarab
#

i told you to check the guild commands

knotty mango
#

In other words, I do not understand what you are asking for me to do

quasi scarab
#

check this collection

#

on the guild where the command is duplicated

knotty quartz
#

asking you to log it in the bot process

#

this would not work in the deploy-commands script since there is no client 😛

knotty mango
#

do i type

guild.commands.delete('ping')
  .then(console.log)
  .catch(console.error);

into deploy-commands.js and run it?

knotty quartz
#

nope
log guild.commands.cache on somewhere like your ready event

knotty mango
#

I am literally autistic /gen
So I'm sorry if I'm being dumb SadLULW

knotty quartz
#

it's perfectly fine

knotty mango
#

does it take a guildId?

knotty quartz
# quasi scarab

client.guilds.cache.get("guildId")
the id of this guild right here

#

you know what, why are we going through so much trouble smh
like it's obvious there's a guild command registered

knotty mango
#

got an [object Map]

knotty quartz
#

@knotty mango you want to remove all the guild-specific commands and just keep the globals right?

knotty mango
#

correcftg

#

correct

quasi scarab
knotty quartz
#

what is there to understand, there's a duplicate, one's a global, one's a guild command

quasi scarab
knotty mango
#

I understand the steps, I understand that we are checking to make sure that the commands are in the actual guild, as well as globally

#

And we are just removing them from the guild side, so it is global only

knotty quartz
#

so in your script, temporary change it to this ts const data = await rest.put( Routes.applicationGuildCommands(clientId, guildId), { body: commands }, ); in there, you don't want any commands, so the body would have an empty array, {body: []} like so

#

running that script afterwards would remove all the guild commands registered to that guild

knotty mango
#

It's fixed now

#

Thanks, Ben Pog
And thank you as well, Mark, I know you're just trying to prevent basic questions flogging #djs-help-v14