discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

Slash Command Builder #5725

Closed DaliborTrampota closed 3 years ago

DaliborTrampota commented 3 years ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Eg. I'm always frustrated when [...] There is no problem, just that it would be cool there is some kind of command builder for slash commands for the upcoming v13.

Describe the ideal solution A clear and concise description of what you want to happen. Not the ideal solution but this is the best my brain could think of during exam season image The types should definitely be declared in separate constants module (like you have) image The add option needs to handle "required" property. The api requires required options be in the options array before the non-required.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered. I dont know what to say here :)

Additional context Add any other context or screenshots about the feature request here. Building slash command with raw objects is fine but it can get really messy. The command builder should be more friendly way of making slashcommands. I wasnt sure how to make the choices but I chose static method createChoice which is a bit more cleaner than { name: "choice name", value: "choice value id" } but this is just an idea I just hope someone will expand upon this and make it even better :). It works just fine to my needs and I have fully working slash command handler with automatic registration on stable v12 djs. Thank you for taking your time and reading this :)

vladfrangu commented 3 years ago

I'm willing to provide the builder I've built in Sapphire, that does validations and provides a simple TS experience, if you want! CC @iCrawl if we want this, where would we put it? It's own repo?

DaliborTrampota commented 3 years ago

I think it should be built-in in djs. Why would it be in separate repo?

vladfrangu commented 3 years ago

I think it should be built-in in djs. Why would it be in separate repo?

So that people can use it outside of discord.js? 👀

DaliborTrampota commented 3 years ago

But this is for discord.js what else would it be for?

DaliborTrampota commented 3 years ago

Like there is embed structure and you can build embed with it there should be slash command structure using which you can also build the command along with other things

kevinbioj commented 3 years ago

But this is for discord.js what else would it be for?

For whoever uses Eris or any other library, or even their own solution.

However I kinda agree with you, I think that separate package should be a dependency of discord.js, and be exported by discord.js to keep consistency with other "helpers" like embeds, buttons & co.

DaliborTrampota commented 3 years ago

Eris should have their own... but thanks.

kyranet commented 3 years ago

Eris should have their own... but thanks.

We maintain and ship discord-api-types freely for everyone using TypeScript, even those using Deno. This would be a very similar thing, and I personally don't see a problem.

Furthermore, we also have -next, which will soon provide very scalable REST and WS handlers, alongside a few more things, and since those don't depend on discord.js (but rather the other way around), nothing stops developers to, theoretically, use those components in their own libraries. And yes, that includes Eris.

DaliborTrampota commented 3 years ago

But will we be able to import/require it from discord.js package? or we have to install yet another package just for this?

DaliborTrampota commented 3 years ago

and is the -next v13? or what exactly is it?

noftaly commented 3 years ago

and is the -next v13? or what exactly is it?

no, -next is a rewrite of djs that is being made here, and will be out when it's ready (not yet). v13 is just the next release with the new features ^^

tipakA commented 3 years ago

But will we be able to import/require it from discord.js package? or we have to install yet another package just for this?

The idea is to have a "main" package, discord.js, as a complete library with all the parts that are needed for it to work already included (as deps). However, in case you wouldn't need entire library, and instead just needed only the REST part of it (or any other), it would be available as a separate package you can use on its own.

Similar thing is already done with Collections for example. Discord.js depends on them thus including them in dependencies directly, but no one stops you from installing only Collections from @discord.js/collection and using them anywhere you want

DaliborTrampota commented 3 years ago

I'm willing to provide the builder I've built in Sapphire, that does validations and provides a simple TS experience, if you want! CC @iCrawl if we want this, where would we put it? It's own repo?

can I see the builder you've made

vladfrangu commented 3 years ago

Anyone can! The code is open source, and available here: https://github.com/sapphiredev/interactions/tree/main/src/lib/structures/builders

I'm willing to make it a package here, just like I did with discord-api-types, but I'll need to talk with the rest of the team first! If we do move it, it'll most likely be re-exported in discord.js (so you'll be able to do import { SlashCommand } from 'discord.js'; for example)

DaliborTrampota commented 3 years ago

Thank I couldn't find the repo before because I have no idea what sapphire is (apart from gemstone :) ) Looks good but is there any example which uses also the options? There is only basic example where you set name and description.

vladfrangu commented 3 years ago
import { SlashCommand } from 'module_name_here';

const owoSlashCommand = new SlashCommand()
    .setName('owo')
    .setDescription('A simple owo command')
    .addBooleanOption(option => option.setName('extra').setDescription('If this owo is EXTRA owo').setRequired(true));

const rawCommand = owoSlashCommand.toJSON(); // or JSON.stringify
DaliborTrampota commented 3 years ago

Indeed, and thanks for the example <3

kyranet commented 3 years ago

JFYI @DaliborTrampota, I deleted the quote because the message is provided directly in the message above, and it was getting harder to read.

Please do not edit those in, and do not quote entire messages that are right above yours, instead, mention the author of the message if anything.