#Commands not refreshing after being correctly deployed

7 messages · Page 1 of 1 (latest)

raven star
#

Good evening. I'm developing a discord.js bot using typescript. I am having trouble using my deployed commands.
To clarify, my bot integration successfully have the commands that I want to deploy but they are not visible within the channel I'm testing on.

Here's my Commands.ts file to register the command and deploy them (public)

import { Client, Routes, SlashCommandBuilder } from "discord.js";
import { REST } from "@discordjs/rest"
import { readdirSync } from "fs";
import { join } from "path";
import { color } from "../functions";
import { SlashCommand } from "../types";

module.exports = (client : Client) => {
    const slashCommands : SlashCommandBuilder[] = []

    let slashCommandsDir = join(__dirname,"../slashCommands")

    readdirSync(slashCommandsDir).forEach(file => {
        if (!file.endsWith(".js")) return;
        let command : SlashCommand = require(`${slashCommandsDir}/${file}`).default
        slashCommands.push(command.command)
        client.slashCommands.set(command.command.name, command)
    })


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

    rest.put(Routes.applicationCommands(process.env.CLIENT_ID), {
        body: slashCommands.map(command => command.toJSON())
    })
    .then((data : any) => {
        console.log(color("text", `🔥 Successfully loaded ${color("variable", data.length)} slash command(s)`))
    }).catch(e => {
        console.log(e)
    })
}

I find out that re-inviting the bot fixed the problem but I don't think this is a normal behaviour, since a public bot should have its command refreshed automatically in any server it's in, right ?

Thanks for your help

spare flowerBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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!
astral heron
#

restart your discord client?

raven star
#

Should anyone restart its discord client to get a bot commands updates ?

astral heron
iron bloom
#

The Discord app caches application commands for a time. Just as it caches everything else. It takes time for the cache to revalidate, but you as a dev usually are eager to test the new commands immediately. So you should reload the app. Your users should be fine as they won‘t try to use them seconds after being deployed usually