#Basehamer999 - Commands
1 messages · Page 1 of 1 (latest)
sup
interactionCreate is an event
sorry if i sound really stupid
You should have 1 handler
so have it check one time for all commands?
So:
interactionCreate {
if command {
do command stuff
} else if autocomplete {
do autocomplete stuff
}
}
Autocompletes in slash commands, are also 'interactions'
So you have to handle the 1 event, for the thing it is
Yea...so instead of having:
if faq
else if two
else if three
What most (and I) do is import all the commands, put them in client.commands and then we find that based on name, and run that directly.
client.on('interactionCreate', async interaction => {
console.log(`Interaction for '${interaction.commandName}'`);
if (!interaction.isCommand()) {
console.log('Interaction is not a command');
return;
}
// Get the command by name
const command = client.commands.get(interaction.commandName);
if (!command) {
console.log('Command is unknown');
return;
}
try {
console.log('Run execute for command');
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
https://pastebin.com/S0TEC8td full script
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
So notice you did client.commands = new Collection(); but did nothing with it
3 commands responds are stored inside the commands folder+his respond so i have to call those plus add the other command
i really losed with what i am doing now
You're half there, but you're trying to implement something new, and keep the old; you can't do that easily.
So I have to move every respond to the main.js?
Your main.js should just handle running the command's execute function
As I have here:
client.on('interactionCreate', async interaction => {
// Get the command by name
const command = client.commands.get(interaction.commandName);
// Run the command's function code
await command.execute(interaction);
});
So having the actually respond somewhere else?
In the command file itself, remember we added execute to it
Not sure on this obsession with respond
Whatever it does, it goes in the command file
So how would my command faq file look then?
import ...;
modules.exports = {
data: new SlashCommandBuilder(...),
execute: async function (interaction) {
// do stuff
},
}
The 'Command' files just handle their data and their execution
Ping me if you need more info
@paper knoll i tried to figure it out myself but i dont know how i could have responds of 3 other commands that have a other way of responding
i dont know if there is a way to have the respond just like other commands in the file with the command itself
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('modpack')
.setDescription('Send the modpack link'),
async execute(interaction) {
await interaction.reply('https://www.curseforge.com/minecraft/modpacks/survival-voxel');
},
};```like this
Sorry what are you asking, what do you mean by "have respondes of 3 other commands"?
i have 3 commands that have there respond build in like this but the faq command needs options which this dont allow me
What do you mean options, like a choice of what to FAQ about?
yea like /faq one /faq two
.addStringOption(option =>
option
.setName('with'.toLowerCase())
.setDescription('What you want Help with.')
.setRequired(true)
.addChoices(...)
)
yea i have that i just need to get the respond up and running https://pastebin.com/mCYYLJ6i like that is the faq command deployer
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
https://pastebin.com/aGzsY6uz and this is my main i am unable to get it responding
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
i know i have client.on 2 times but i dont know how i would combine it
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
You don't do anything with commandFiles you want to stick them in client.commands so that on interactionCreate you can go:
let command = client.commands.get(interaction.commandName);
...
await command.execute(
interaction,
);
i am getting confused
why is javascript so much harder then lua
maybe i need to start over
yea i understand that its just the part that explains the option dont match with the first part
What's wrong with the options.
If you have an option e.g. like line called with then you just access it with what I shared earlier when your command's function runs
but they explain how to get the respond in the main file but the other part explains how to get it in a seperate file
Are you referring to this bit?
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
if (commandName === 'ping') {
await interaction.reply('Pong!');
} else if (commandName === 'beep') {
await interaction.reply('Boop!');
}
});
that was first after that he explained to move it to a specefic file in the commands folder
Yea, it's explaining in steps.
First just saying "look you can use commandName to run the right code"
Then it advances to using a collection, to run the command via a file, rather than if/else if/else if/else if/else if/else if/else if/else if/else if
yep and i understand that
but the option command dont explain how to add them inside his own file
What do you mean "option command"
Share a screenshot or code of the bit in the guide you're referring to