astro
astro
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
Do I just put the slashcommandbuilder in deploy-commands instead and just have the subcommands be formatted as JSON (removing the .toJSON() when pushing subcommands)
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
How would I "handle" it if it is a directory
30 replies
DIAdiscord.js - Imagine an app
Created by Time on 5/3/2024 in #djs-questions
application did not respond
unless you're doing that in your command's file, and if so that's outside the scope of my knowledge capacity atm
16 replies
DIAdiscord.js - Imagine an app
Created by Time on 5/3/2024 in #djs-questions
application did not respond
i mean... yeah.. you're doing deferReply() but aren't resolving that in any way
16 replies
DIAdiscord.js - Imagine an app
Created by Time on 5/3/2024 in #djs-questions
application did not respond
where is the first bit of code located
16 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
right, but how can i make it recognize the folder as a "command", and what should I put inside of the data field in module.exports for the subcommands?
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
So something like this?
for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath);

// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const commandFiles = fs.statSync(filePath);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath);

// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const commandFiles = fs.statSync(filePath);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
oh do you want me to have both fs.readdirSync and fs.statSync in the same loop?
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
yes but then the other for loop errors
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
Like, unless I change it from
const commandFiles = fs.readdirSync(commandsPath);
const commandFiles = fs.readdirSync(commandsPath);
to
const commandFiles = fs.statSync(commandsPath);
const commandFiles = fs.statSync(commandsPath);
I can't do it, but if I do this, will it change anything?
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
or none that i can see at least
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
how can i check if soemthing is a directory though? there's no isDirectory or anything similar
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
just want to make sure i understood you right before i go on a ghost hunt
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
okay so what i've figured out is that the for (const folder of commandFolders) loop basically takes command files from within any folders inside of the commands folder (im assuming this is so you can label the command types? like dev commands, mod commands etc.) now, do i need to make another for of loop inside of that to check if there is another directory, and make a slashcommandbuilder... inside of deploy-commands.js?
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
oop
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
My current deploy-commands.js looks like this
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');

const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// Construct and prepare an instance of the REST module.
const rest = new REST().setToken(token);

// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');

const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// Construct and prepare an instance of the REST module.
const rest = new REST().setToken(token);

// and deploy your commands!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
coming back to this, how would i edit the deploy-commands.js file in order to make it do the following - read all the files inside commands/utility as, obviously, commands - read all files in any potential subdirectories within the utility directory, and it would automatically know that if the filetype that it's reading is a directory, that directory name is the slash command name and any modules inside it are just subcommands
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
nevermind, i'll try to work on it, you gave me an idea
30 replies
DIAdiscord.js - Imagine an app
Created by astro on 4/26/2024 in #djs-questions
Command handler change
what do you mean
30 replies