Commands not refreshing after being correctly deployed

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)
})
}
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
5 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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!
darp
darp10mo ago
restart your discord client?
Sourceae
SourceaeOP10mo ago
This actually worked but is this the expected behaviour ? Should anyone restart its discord client to get a bot commands updates ?
darp
darp10mo ago
discord client is just bad at syncing them
Sourceae
SourceaeOP10mo ago
Thanks for the clarification 🙏
Want results from more Discord servers?
Add your server