#I am so confused about your description
1 messages · Page 1 of 1 (latest)
Totally understand. If you are using the deploy-commands.js file then what that does is it packages up the command data into a format that is Discord backend friendly. This must specifically go through a POST HTTP request from our end to Discord's.
What I suggested as a solution to your problem was to use the part of the deploy-commands.js file to fire using a variable guildId parameter instead of only being able to run if it imports a guildId before the program runs.
Totally understand. What I was suggesting you do was repurpose the part of deploy-commands.js to take in a variable parameter guildId instead of only importing in from a static file before you run it
How would i do this?
So from the part where you find the path to the commands file to bottom of the file, try taking that into a separate file and creating it as an independent function
Something like const addCommandsToNewGuild = async (guildId) => { //function here//}
glob(`${process.cwd()}/Commands/*/*.js`, function(err, files) {
files.map((file) => {
const command = require(file);
if(!command.name) {
delete require.cache[require.resolve(file)];
return console.log(`${file.split("/").pop()} does not have a command name! Removing the command.`)
}
if(command.public) {
public_CommandsArray.push(command);
console.log(`Loaded ${command.name.toUpperCase()} from ${file.split("/").pop()}`)
} else {
dev_CommandsArray.push(command);
console.log(`Loaded ${command.name.toUpperCase()} from ${file.split("/").pop()}`)
}
client.commands.set(command.name, command);
delete require.cache[require.resolve(file)];
});
(async () => {
const guild = client.guilds.cache.get(devGuildID);
await guild.commands.set(dev_CommandsArray);
console.log(`${client.user.tag} | Loaded ${public_CommandsArray.length} global commands`);
console.log(`${client.user.tag} | Loaded ${dev_CommandsArray.length} developer commands`);
})
});
But isn't that the full code..
This is part of the file but the guide walks through the full deployment set-up. I'd highly recommend checking it out for usage with your own commands. Do you mind if I ask how you set up your commands? Are they deploying to Discord?
The function would also encapsulate nearly the whole file body. The file itself as written in the guide is essentially one big function that just gets called automatically by running node deploy-commands.js
I have followed an youtuber who has instructed in how to set it up, so i can't really change that now
Yeah I understand. Well I'm not familiar with the glob package but wouldn't something like this work
const addNewCommandsToNewGuild = async (NEW_GUILDID) => { // Wrapped function
glob(`${process.cwd()}/Commands/*/*.js`, function(err, files) {
files.map((file) => {
const command = require(file);
if(!command.name) {
delete require.cache[require.resolve(file)];
return console.log(`${file.split("/").pop()} does not have a command name! Removing the command.`)
}
if(command.public) {
public_CommandsArray.push(command);
console.log(`Loaded ${command.name.toUpperCase()} from ${file.split("/").pop()}`)
} else {
dev_CommandsArray.push(command);
console.log(`Loaded ${command.name.toUpperCase()} from ${file.split("/").pop()}`)
}
client.commands.set(command.name, command);
delete require.cache[require.resolve(file)];
});
(async () => {
const guild = client.guilds.fetch(NEW_GUILDID); *** New parameter
await guild.commands.set(dev_CommandsArray);
console.log(`${client.user.tag} | Loaded ${public_CommandsArray.length} global commands`);
console.log(`${client.user.tag} | Loaded ${dev_CommandsArray.length} developer commands`);
})
});
}
and you'd just remove the public part of this as well. Are you using global and public interchangeably? And dev_commands as guild commands?
then you could export addNewCommandsToNewGuild and call it in the guildCreate event
Good luck!
Yes that part of the code looks good to me, just take out my junk **** New parameter comment there
Where are you calling this whole exported function? If its not reading client it means that there's no client object being passed through into it
it isn't being exported, should it?
It is being exported somewhere. That's what the module.exports is doing
Like this?
That was the old handler
Ahh I'm sorry I think I might be sending too much in not so clear ways. The handler as you've written it won't be functional even if you do pass in a client object. This is my comment from before without the comments. As its written now, you can pass in a guildId and a client. Try this from your Event handler on guildCreate which emits a Guild object. you can get the guild.id and guild.client from the guild object
const addNewCommandsToNewGuild = async (NEW_GUILDID, client) => {
glob(`${process.cwd()}/Commands/*/*.js`, function(err, files) {
files.map((file) => {
const command = require(file);
if(!command.name) {
delete require.cache[require.resolve(file)];
return console.log(`${file.split("/").pop()} does not have a command name! Removing the command.`)
}
if(command.public) {
public_CommandsArray.push(command);
console.log(`Loaded ${command.name.toUpperCase()} from ${file.split("/").pop()}`)
} else {
dev_CommandsArray.push(command);
console.log(`Loaded ${command.name.toUpperCase()} from ${file.split("/").pop()}`)
}
client.commands.set(command.name, command);
delete require.cache[require.resolve(file)];
});
(async () => {
const guild = client.guilds.fetch(NEW_GUILDID);
await guild.commands.set(dev_CommandsArray);
console.log(`${client.user.tag} | Loaded ${public_CommandsArray.length} global commands`);
console.log(`${client.user.tag} | Loaded ${dev_CommandsArray.length} developer commands`);
})
});
}