Problem with the loading of 3 commands

hello ! I've a problem with 3 of my commands, that load properly but they are not shown in the discord integrations of the discord settings of my server, they are showed when i use bot.command.forEach but still can't use them
5 Replies
d.js toolkit
d.js toolkit15mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Syjalo
Syjalo15mo ago
Did you deploy them?
Doraa
Doraa15mo ago
Yes, all my others commands work, and they use the same method to load
const Discord = require("discord.js")
const { REST } = require("@discordjs/rest")
const { Routes } = require("discord.js")

module.exports = async bot => {

let commands = []

bot.commands.forEach(async command => {

let slashcommand = new Discord.SlashCommandBuilder()
.setName(command.name)
.setDescription(command.description)
.setDMPermission(command.dm)
.setDefaultMemberPermissions(command.permission === "Aucune" ? null : command.permission)

if(command.options?.length >= 1 ){
for(let i = 0; i < command.options.length; i++) {
console.log(command)
if (command.name === "say") {
if (i === 0) {
slashcommand[`add${command.options[i].type.slice(0, 1).toUpperCase() + command.options[i].type.slice(1, command.options[i].type.length)}Option`](option => option.setName(command.options[i].name).setDescription(command.options[i].description).setRequired(command.options[i].required).addChoices(...command.options[0].choices))
}
else {
slashcommand[`add${command.options[i].type.slice(0, 1).toUpperCase() + command.options[i].type.slice(1, command.options[i].type.length)}Option`](option => option.setName(command.options[i].name).setDescription(command.options[i].description).setRequired(command.options[i].required))
}
}
else {
slashcommand[`add${command.options[i].type.slice(0, 1).toUpperCase() + command.options[i].type.slice(1, command.options[i].type.length)}Option`](option => option.setName(command.options[i].name).setDescription(command.options[i].description).setRequired(command.options[i].required))
}
}
await commands.push(slashcommand)
}
})

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

await rest.put(Routes.applicationCommands(bot.user.id), {body: commands})
console.log("les slashcommandes sont créées avec succès !")
}
const Discord = require("discord.js")
const { REST } = require("@discordjs/rest")
const { Routes } = require("discord.js")

module.exports = async bot => {

let commands = []

bot.commands.forEach(async command => {

let slashcommand = new Discord.SlashCommandBuilder()
.setName(command.name)
.setDescription(command.description)
.setDMPermission(command.dm)
.setDefaultMemberPermissions(command.permission === "Aucune" ? null : command.permission)

if(command.options?.length >= 1 ){
for(let i = 0; i < command.options.length; i++) {
console.log(command)
if (command.name === "say") {
if (i === 0) {
slashcommand[`add${command.options[i].type.slice(0, 1).toUpperCase() + command.options[i].type.slice(1, command.options[i].type.length)}Option`](option => option.setName(command.options[i].name).setDescription(command.options[i].description).setRequired(command.options[i].required).addChoices(...command.options[0].choices))
}
else {
slashcommand[`add${command.options[i].type.slice(0, 1).toUpperCase() + command.options[i].type.slice(1, command.options[i].type.length)}Option`](option => option.setName(command.options[i].name).setDescription(command.options[i].description).setRequired(command.options[i].required))
}
}
else {
slashcommand[`add${command.options[i].type.slice(0, 1).toUpperCase() + command.options[i].type.slice(1, command.options[i].type.length)}Option`](option => option.setName(command.options[i].name).setDescription(command.options[i].description).setRequired(command.options[i].required))
}
}
await commands.push(slashcommand)
}
})

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

await rest.put(Routes.applicationCommands(bot.user.id), {body: commands})
console.log("les slashcommandes sont créées avec succès !")
}
this one
const Discord = require('discord.js');

module.exports = {
name: "ping",
description: "Obtenez le ping/la latence du bot",
dm: true,
category: "Informations",
permission: "Aucune",
usage: "/ping",

async run(bot, message) {
let pingEmbed = new Discord.EmbedBuilder()
.setAuthor({ name: message.user.username, iconURL: message.user.displayAvatarURL({ dynamic: true }) })
.setDescription(`Ping : \`${bot.ws.ping}ms\``)
.setColor('Green')
await message.reply({embeds: [pingEmbed]});
}
}
const Discord = require('discord.js');

module.exports = {
name: "ping",
description: "Obtenez le ping/la latence du bot",
dm: true,
category: "Informations",
permission: "Aucune",
usage: "/ping",

async run(bot, message) {
let pingEmbed = new Discord.EmbedBuilder()
.setAuthor({ name: message.user.username, iconURL: message.user.displayAvatarURL({ dynamic: true }) })
.setDescription(`Ping : \`${bot.ws.ping}ms\``)
.setColor('Green')
await message.reply({embeds: [pingEmbed]});
}
}
This is one of the command that didnt show up, but it show as loaded in my console
const fs = require('fs');

module.exports = async bot => {
fs.readdirSync('./Commandes').filter(f => f.endsWith('.js')).forEach(async file =>{
let command = require(`../Commandes/${file}`);
if (!command.name || typeof command.name !== "string") throw new TypeError(`${file} n'a pas de nom ou le nom n'est pas une chaîne de caractères`)
bot.commands.set(command.name, command);
console.log(`Commande chargée: ${command.name} avec succes !`);
})
}
const fs = require('fs');

module.exports = async bot => {
fs.readdirSync('./Commandes').filter(f => f.endsWith('.js')).forEach(async file =>{
let command = require(`../Commandes/${file}`);
if (!command.name || typeof command.name !== "string") throw new TypeError(`${file} n'a pas de nom ou le nom n'est pas une chaîne de caractères`)
bot.commands.set(command.name, command);
console.log(`Commande chargée: ${command.name} avec succes !`);
})
}
and the method i use to check all commands files
Syjalo
Syjalo15mo ago
Commands array should be an array of command data, not builders. You should have received an error. Use commands.push(slashcommand.toJSON())
Doraa
Doraa15mo ago
i didnt have any error so i changed and it is still the same guess it is not from that i really don't understand oh i see where the problem is, it is only for commands that didnt have any option My bad, that was just a scope error thanks ! thanks @joe376 too