#deploying slash commands properly

44 messages · Page 1 of 1 (latest)

ivory hill
#

i have a issue where my old slash commands are staying there forever, so i want to make a function that refreshes a guild, adds slash commands that dont exist, updates ones that exist, and deletes ones that dont exist in the code anymore, then ill also make a global function to refresh all guilds (which takes 1 hour, so thats why i also want a one-guild refresh one to allow for bot testing)

how do i go about making this, i already have a basic deploy commands

cinder ospreyBOT
#
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
sullen ore
#

global commands no longer take an hour to update, so recreating global commands by deploying every command as a guild command in every guild is unnecessary
using the "bulk overwrite commands" endpoint (making a PUT request to the appropriate endpoint) already creates, updates, and deletes commands all in one go, so if you followed the guide's deployment, that's all you should need

#

if you're observing old commands persisting beyond refreshing your discord client, then it's possible these are left over from the unnecessary guild command deployment

ivory hill
#

or should i keep it manual

sullen ore
#

that'd be completely unnecessary unless you change your commands on every launch (which you should not be doing)
it's recommended to keep it manual

ivory hill
#

alright

#

do you have some tutorial for the newest command deployment to make it easier for me or?

#

ill probably get some stuff wrong so tutorial would be good

sullen ore
#

I'm not sure what you mean by "the newest command deployment"
it hasn't changed since application commands were released, so if you already followed the guide, that's all you should need

ivory hill
#
require("dotenv").config();
const { DISCORD_TOKEN: token } = process.env;
const { REST, Routes } = require("discord.js");
const { commands } = require("../models/commandSchema");

const commands_int_data = [];

for (const command of commands) {
  commands_int_data.push(command.data.toJSON());
}

const rest = new REST({ version: "10" }).setToken(token);

(async () => {
  try {
    console.log(`Deploying ${commands.length} commands to guild!`)

    const data = await rest.put(
      Routes.applicationCommands(),
      { body: commands }
    );

    console.log(`Successfully refreshed ${data.length} slash commands!`)
  } catch (error) {
    console.error(error);
  }
})();

?

sullen ore
#

on the assmption you intend to put your client id in Routes.applicationCommands() at some point, sure

ivory hill
#

right missed that one

ivory hill
# sullen ore on the assmption you intend to put your client id in `Routes.applicationCommands...
require("dotenv").config();
const { DISCORD_TOKEN: token, CLIENT_ID: clientId } = process.env;
const { REST, Routes } = require("discord.js");
const { commands } = require(`./models/commandSchema`);

const commands_int_data = [];

for (const commandName in commands) {
  const command = commands[commandName];
  commands_int_data.push(command.int_data.toJSON());
}

console.log(commands_int_data);

const rest = new REST({ version: "10" }).setToken(token);

(async () => {
  try {
    console.log(`Deploying ${commands_int_data.length} commands to guild!`);

    const data = await rest.put(Routes.applicationCommands(clientId), {
      body: commands_int_data,
    });

    console.log(`Successfully refreshed ${data.length} slash commands!`);
  } catch (error) {
    console.error(error);
  }
})();

the old slash commands are still remaining?

sullen ore
ivory hill
#

im not sure what to do

sullen ore
#

the route you used to deploy them determines whether they're guild/global
Routes.applicationCommands() is for global commands
Routes.applicationGuildCommands() is for guild commands
therefore if you're only bulk overwriting global commands, guild commands won't be deleted (and vice versa)

ivory hill
#

ah

#

do i kick my bot and add him back?

#

would that solve

sullen ore
#

I mean I suppose that would instantly remove guild commands for that guild

broken shadowBOT
#

If you have duplicate commands on your server, you registered both global and guild commands.

You can remove the duplicates by resetting either the global or guild commands

  • Resetting global commands: rest.put(Routes.applicationCommands(clientId), { body: [] })
  • Resetting guild commands: rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: [] })
sullen ore
#

you could also do this

ivory hill
#

i have readded the bot it worked, but the new commands are not being created

#

no errors or nothing

sullen ore
#

how have you determined this?
do they entirely not appear in the integrations tab of your server's settings?
when deploying did it log Successfully refreshed n slash commands!?

ivory hill
#
Successfully refreshed 1 slash commands!```
yep
#

let me check integrations

#

so there is a /balance command but its not appearing at all when typing /

ivory hill
#

yes

#

this time it worked upon restaritng

#

not the first

#

and i have to use task manager

#

could i prevent that discord has to be fully restarted

#

including its processes

#

do you recommend adding a response that the command doesnt exist, and they should restart discord with the task manager

#

to refresh the slash commands

#

it is a little annoying to test the bot aswell

sullen ore
#

could i prevent that discord has to be fully restarted including its processes
frankly the distinction makes me think you're unaware that you have the "Minimize to Tray" option enabled
the process is discord
it doesn't have to be restarted with the task manager, and because of electron, you can just use ctrl + r
do you recommend adding a response that the command doesnt exist, and they should restart discord with the task manager
that's entirely up to you, but discord also has some built in error messages relating to this

ivory hill
#

alright Ctrl + R works well enough

#

thanks duck