Can't deploy slash commands!

I can't deploy my slash commands, its just doesn't give any error, i dont get it
9 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
CanineData
CanineData2y ago
Read the bullet points
Kryp Arnold
Kryp Arnold2y ago
what is that
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
CanineData
CanineData2y ago
What's the error?
Kryp Arnold
Kryp Arnold2y ago
import { ApplicationCommandDataResolvable, REST, SlashCommandBuilder, Routes, ChatInputCommandInteraction} from "discord.js";
import { config } from "dotenv";
import { readdirSync } from "fs";
import * as path from "path";
config();

export interface SlashCommand{
data: SlashCommandBuilder,
execute(interaction: ChatInputCommandInteraction): Function;
}

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

const commandsPath: string = path.join(__dirname,"../slashCommands/");

const commandFiles: string[] = readdirSync(commandsPath).filter(file => file.endsWith(".cjs"));

const commands: ApplicationCommandDataResolvable[] = [];

commandFiles.forEach(file => {
const command: SlashCommand = require(commandsPath + file);
commands.push(command.data.toJSON());
});

(async () => {
try {
await rest.put(
Routes.applicationCommands(process.env.ID),
{body:commands}
).then(() => {console.log(`Loaded ${commands.length} (/) Slash Commands...`)});
} catch (error) {

}


})();
import { ApplicationCommandDataResolvable, REST, SlashCommandBuilder, Routes, ChatInputCommandInteraction} from "discord.js";
import { config } from "dotenv";
import { readdirSync } from "fs";
import * as path from "path";
config();

export interface SlashCommand{
data: SlashCommandBuilder,
execute(interaction: ChatInputCommandInteraction): Function;
}

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

const commandsPath: string = path.join(__dirname,"../slashCommands/");

const commandFiles: string[] = readdirSync(commandsPath).filter(file => file.endsWith(".cjs"));

const commands: ApplicationCommandDataResolvable[] = [];

commandFiles.forEach(file => {
const command: SlashCommand = require(commandsPath + file);
commands.push(command.data.toJSON());
});

(async () => {
try {
await rest.put(
Routes.applicationCommands(process.env.ID),
{body:commands}
).then(() => {console.log(`Loaded ${commands.length} (/) Slash Commands...`)});
} catch (error) {

}


})();
it prints "Loaded 2 Slash Commands" and nothing code keep running its a cts code thats my SlashCommandLoader.cts file is there anything wrong
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Kryp Arnold
Kryp Arnold2y ago
Kryp Arnold
Kryp Arnold2y ago
still same dont mind the ExperimentalWarning, its just a warning for importing json i just tried it with normal .js file and it worked fine idk why but its not working on typescript it works if you make your file extension "cts" when you make your file extension "cts", node.js acts like its a commonjs file builder converts it very good wait i'll send you builded code yeah i said cjs to make people understand easily i was about to say that i need to use require because import can be used top of the code i was trying it i'll let you know if it works
const commandFiles = readdirSync(commandsPath).filter(file => file.endsWith(".cjs"));
const commands = [];
for (let file of commandFiles) {
let command;
import("file:\\"+commandsPath + file).then((module) => {
command = module.default
console.log(command)
});

commands.push(command.data.toJSON());
}
const commandFiles = readdirSync(commandsPath).filter(file => file.endsWith(".cjs"));
const commands = [];
for (let file of commandFiles) {
let command;
import("file:\\"+commandsPath + file).then((module) => {
command = module.default
console.log(command)
});

commands.push(command.data.toJSON());
}
commands.push(command.data.toJSON());
^

TypeError: Cannot read properties of undefined (reading 'data')
commands.push(command.data.toJSON());
^

TypeError: Cannot read properties of undefined (reading 'data')
import() doesnt work properly oh i have to use await i figured it out in my reactRole.cjs file (its a slashcommand file) importing another file which has interval in it and it causes code wont stop and rest doesn't save finally