#No change

1 messages · Page 1 of 1 (latest)

astral oyster
#

Okay

#

Figured we just start a thread

heady gazelle
#

Good idea

astral oyster
#

@dusty kettle can you put the code into a code block here?

dusty kettle
#

one moment - i just wanna try an idea i thought of

dusty kettle
# astral oyster <@625039247564341278> can you put the code into a code block here?
require("dotenv").config()

const fs = require("node:fs")
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord.js');

async function deploy(){
let commands = []

const clientId = "1016395817768198225"
const guildId = "1010447900737818647"

const module = fs.readdirSync("./src/modules");
for (const dir of module) {
    const directory = fs.readdirSync(`./src/modules/${dir}/commands`)
    for (const file of directory) {
        const command = require(`./src/modules/${dir}/commands/${file}`)
        commands.push(command.data.toJSON())
    }
}

const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN);
console.log(commands)
    try {
        console.log('Started refreshing application (/) commands.');

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

    } catch (error) {
        console.error(error);
    }
}

deploy()

This is the whole file, I just tried to see if it would work if i made a deploy.js file, it did not.

astral oyster
#

what is deploy()

#

Further, send one of your command files if possible

#

at least the export portion

#

For reference, this is what my (ES6, so using import instead of require) deploy.js looks like. It functions.

import 'dotenv/config' 
import { Routes, REST } from 'discord.js';
import fs from 'node:fs';


const token = process.env.TOKEN;
const clientId = process.env.CLIENT;

const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const command = await import(`./commands/${file}`);
    commands.push(command.default.data.toJSON());
}

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

(async () => {
    try {
        console.log('Started refreshing application (/) commands.');

        await rest.put(
            Routes.applicationCommands(clientId),
            { body: commands },
        );

        console.log('Successfully reloaded application (/) commands.');
    } catch (error) {
        console.error(error);
    }
})();```
#

Oh, get rid of 'discordjs/rest' require

#

it's just const { REST, Routes } = require('discord.js'); now

dusty kettle
astral oyster
#

A tiny bit

#

Should also have the try/catch block outside the async/await but

#

do it how it works for now

dusty kettle
#

yeah, gimme a sec computers being slow

astral oyster
#

What is the command file though

#

because I'm using ES6 I need to do command.default.data rather than just command.data

dusty kettle
astral oyster
#

huh

#

strange

#

No worries at all though, glad it worked for ya

dusty kettle
#

🙂

astral oyster
#

I highly suggest swapping to ES6 by the way

#

Looking like we're moving that way anyhow

dusty kettle