#No change
1 messages · Page 1 of 1 (latest)
Good idea
@dusty kettle can you put the code into a code block here?
one moment - i just wanna try an idea i thought of
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.
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
Ah, the documentation is out of date (discordjs.guide). Let me try that though
A tiny bit
Should also have the try/catch block outside the async/await but
do it how it works for now
yeah, gimme a sec computers being slow
What is the command file though
because I'm using ES6 I need to do command.default.data rather than just command.data
Thank you so much for your help, it appears that the issue wasn't discord.js but discord.
The command appears on mobile, but not on PC.
🙂
I highly suggest swapping to ES6 by the way
Looking like we're moving that way anyhow
yeah i will defo move to es6 soon - i just wanna quickly rough up the idea i have before coding it properly.