Filter lists down to only used inputs

This commit is contained in:
Nathaniel Mason 2022-04-22 06:22:02 +01:00
parent 37e0603ebf
commit 984aaecc53
3 changed files with 21 additions and 20 deletions

View File

@ -19,7 +19,8 @@ module.exports = {
}, },
async parseInteraction (client, config, interaction) { async parseInteraction (client, config, interaction) {
await interaction.reply(this.handle(client, config, interaction.user, [...Array(10).keys()].map(i => interaction.options.getString(`option${i + 1}`)))); console.log([...Array(10).keys()].map(i => interaction.options.getString(`option${i + 1}`)).filter(str => str));
await interaction.reply(this.handle(client, config, interaction.user, [...Array(10).keys()].map(i => interaction.options.getString(`option${i + 1}`)).filter(str => str)));
}, },
handle (client, config, user, options) { handle (client, config, user, options) {

View File

@ -16,7 +16,7 @@ module.exports = {
}, },
async parseInteraction (client, config, interaction) { async parseInteraction (client, config, interaction) {
await interaction.reply(this.handle(client, config, interaction.user, [...Array(10).keys()].map(i => interaction.options.getString(`option${i + 1}`)))); await interaction.reply(this.handle(client, config, interaction.user, [...Array(10).keys()].map(i => interaction.options.getString(`option${i + 1}`)).filter(str => str)));
}, },
handle (client, config, user, args) { handle (client, config, user, args) {
@ -25,7 +25,7 @@ module.exports = {
let returnMessage = ''; let returnMessage = '';
args.forEach(async (arg) => { args.forEach(async (arg) => {
const commandName = arg.toLowerCase(); const commandName = arg?.toLowerCase();
const command = client.commands.get(commandName) || const command = client.commands.get(commandName) ||
client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));

View File

@ -32,27 +32,27 @@ client.generateErrorMessage = (errorMsg, avatarURL) => ({
client.on('error', (e) => console.log(`[ERROR] ${e}`)); client.on('error', (e) => console.log(`[ERROR] ${e}`));
client.on('warn', (e) => (`[WARN] ${e}`)); client.on('warn', (e) => (`[WARN] ${e}`));
client.once('ready', async () => { client.once('ready', async () => {
const commands = config.sandbox ? client.guilds.cache.get(config.sandboxGuild)?.commands : client.application.commands; // const commands = config.sandbox ? client.guilds.cache.get(config.sandboxGuild)?.commands : client.application.commands;
// Be careful about running the code below, there's a 200-per-day limit on creating slash commands // Be careful about running the code below, there's a 200-per-day limit on creating slash commands
if (config.sandbox) { // if (config.sandbox) {
console.log('deleting previous commands from sandbox'); // console.log('deleting previous commands from sandbox');
const localCommands = await commands.fetch(); // const localCommands = await commands.fetch();
localCommands.forEach(async x => { // localCommands.forEach(async x => {
await commands.delete(x); // await commands.delete(x);
}); // });
console.log('deleting global commands'); // console.log('deleting global commands');
const globalCommands = await client.application.commands.fetch(); // const globalCommands = await client.application.commands.fetch();
globalCommands.forEach(async x => { // globalCommands.forEach(async x => {
await client.application.commands.delete(x); // await client.application.commands.delete(x);
}); // });
} // }
client.commands.forEach(async command => { // client.commands.forEach(async command => {
await commands.create(command); // await commands.create(command);
console.log(command); // console.log(command);
}); // });
console.clear(); console.clear();
console.log(' ___ _ __ '); console.log(' ___ _ __ ');