discordjs / builders Goto Github PK
View Code? Open in Web Editor NEWA collection of builders that you can use when creating your bot.
License: Apache License 2.0
A collection of builders that you can use when creating your bot.
License: Apache License 2.0
Please revert back the validation errors. This new "Zod" thing is terrible. I've been searching for 2h where the issue is because it doesn't tell you where the error is.
Revert back to the previous validator (ow) which said what exact fields and commands are causing issues
No response
the first image, I'm missing description for one command, there is no way for me to read that from the error.
the second image, I accidentally made one command name first letter capital. All I know that my regex is invalid somewhere in 50 commands. This is terrible
Is your feature request related to a problem? Please describe.
A handful of users have had complaints of builders not being directly compatible with djs methods. This is because this library uses api-types which is expected and somewhat intended.
Describe the ideal solution
Instead I'm proposing we introduce Builder#toData
. This is basically just like toJSON
but instead gives you the djs *Data
equivalent type. This allows the builders to be used with djs, and not require any implementation changes in djs.
Describe alternatives you've considered
Some of have brought up the solution of allowing djs methods to accept both api-types and djs data. However as others have stated this seems out of place for the djs library.
Is your feature request related to a problem? Please describe.
No, this feature request is not related to any problem with the library at the moment.
Describe the ideal solution
There are frequently times in my code where I would like to present a dynamic list of strings to a user. Sometimes, this list is separated by commas due to its length. A builder would be useful here to perform the tedious formatting for me.
[] => ''
['alpha'] => 'alpha'
['alpha', 'beta'] => 'alpha or beta'
['alpha', 'beta', 'gamma'] => 'alpha, beta, or gamma'
There should be an option to select whether the option should be with and
or with or
. Additionally, there should be a boolean for the Oxford comma no-believers.
Describe alternatives you've considered
The obvious other option would be to construct my own builder but it might be better to include it in this library as a common function for other developers out there.
Additional context
Please ask specific questions relating to this request as necessary. Nothing else to add! :)
New discord API change added support to specify channel type for channel option for slash commands
https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure
I'd like to request addition for this feature in this library
https://github.com/discordjs/builders/blob/main/src/interactions/slashCommands/options/channel.ts
I'd do it myself but I don't know how to go about this in this repo so I keep it for the more experienced ones :)
Also I'd like to request an unblock from this repo on my main account https://github.com/DaliborTrampota as you can see I'm not here to cause any troubles, I already reported one bug and it was fixed discordjs/discord.js#6667
and working on writing down another one bug.
Please add context menus to the package
So maybe add an option were we could choose between / and content when making our code. Here is an example
const { SlashCommandBuilder } = require('@discordjs/builders');
const Discord = require('discord.js')
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!')
.setType(type),
async execute(interaction) {
await interaction.reply('Pong')
},
};
Is your feature request related to a problem? Please describe.
Add builders for Discord User commands and Message commands
Describe the ideal solution
Create abstract CommandBuilder (instead of SlashCommandBuilder) with support for User and Message commands
Describe alternatives you've considered
Create alternative builders for each command type
Discord.js has recently added support for autocomplete, but I am being held back by this library, not including support for it, please add this!
I am sure a solution would be as simple as any other option!
No response
No response
Is your feature request related to a problem? Please describe.
There is currently no option to select the acceptable range of integers for the .addIntegerOption()
on the SlashCommandBuilder()
. This has to partially do with Discord's API for creating slash commands. When they do implement the feature, I would like to support added here. (I am also not sure where to provide such feedback to Discord.)
Describe the ideal solution
The ideal option would be to have an extra method on the integer to select ranges of integers that are acceptable for the option. The method should default to the full range when no ranges are provided. The builder should provide warnings when integer ranges overlap in some method to the developer. In addition, the builder should allow a step feature for cases that the developer wants to only select ranges in steps of 2, 3, 4, 5, etc.
Describe alternatives you've considered
The alternative option would be to manually check the integer option(s) passed with their acceptable range and send an ephemeral message to the user who invocated the slash command to let them the number is out of range. This, however, is very clunky because it includes about five extra lines per option to validate.
Additional context
Discord Slash commands are useful for bot builders because they simplified interactions with users through a select range of options making it unnecessary to lint all responses with a regular expression for correctness. This problem seems like something that would be best fixed on Discord's side rather than on the consumer side of the library.
Is your feature request related to a problem? Please describe.
I create my slash commands in each of their own files. Each file exports a constant variable whose value is constructed using the slash command builder at runtime.
Describe the ideal solution
Add something like this in SlashCommandBuilder.d.ts
:
type SlashCommandJSON = {
name: string;
description: string;
options: APIApplicationCommandOption[];
default_permission: boolean | undefined;
};
export default SlashCommandJSON;
Describe alternatives you've considered
The alternative is for me to create that file for myself and just reuse it for other projects.
Additional context
No additional context to provide.
I suggest we add the MessageEmbed
class. I'm more than happy to take on the task.
Is your feature request related to a problem? Please describe.
Could it be possible to have a builder compatible with https://discord.js.org/#/docs/main/stable/class/ApplicationCommand ?
Describe the ideal solution
A build like the existing SlashCommandBuilder but that output something usable directly with discord.js without having to create a REST instance ourself (and that typescript will be happy of).
Describe alternatives you've considered
None.
Additional context
None.
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/interactions/slashCommands/mixins/CommandOptionWithChoices' is not defined by "exports" in C:\Users\NORI\Documents\D
iscord\bots\bp\node_modules@discordjs\builders\package.json
how could i fix that
This issue is caused by ow, as the code below shows.
This issue did not occur on v0.7.x.
edit: sindresorhus/ow#215
import { SlashCommandBuilder } from '@discordjs/builders';
new SlashCommandBuilder();
// or
import ow from 'ow';
ow.string.minLength(1); // ow.string is undefined
0.8.1
16.13.0
Windows
High (immediate attention needed)
Please describe the problem you are having in as much detail as possible:
According to the documentation, there should be a way to create a number option on slash commands via the SlashCommandBuilder() (see here and here). However, when attempting to use .addNumberOption
, this error is thrown:
.addNumberOption(option =>
^
TypeError: (intermediate value).setName(...).setDescription(...).addNumberOption is not a function
Upon going into the files for discord.js, there does not seem to be any support for number options within @discordjs/builders/dist/interactions/slashCommands/options
.
Include a reproducible code sample here, if possible:
new SlashCommandBuilder()
.setName('cmdname')
.setDescription('command description')
.addNumberOption(option =>
option.setName('value')
.setDescription('the value')
.setRequired(true))
Further details:
Relevant client options:
Is your feature request related to a problem? Please describe.
I am writing a little helper library that allows builders from this library to double as the structure for a command execution framework. It would be helpful if SlashCommandBuilder
and SlashCommandSubcommandBuilder
had something like a setHandler(function)
method to associate a command execution handler function with a command. Is this something the team considers within the scope of this library?
Describe the ideal solution
I would like to bundle a handler function in with a SlashCommandBuilder
and SlashCommandSubcommandBuilder
. Something like:
const builder = new SlashCommandBuilder()
.setHandler(function(interaction) { ... });
/*
SlashCommandBuilder {
options: [],
name: undefined,
description: undefined,
defaultPermission: undefined,
handler: [Function (anonymous)]
}
*/
Describe alternatives you've considered
I am currently injecting this function directly into the builder prototypes. I do this instead of extending the classes so I can avoid needing to reimplement the addSubcommand
function to change new SlashCommandSubcommandBuilder()
to my subclass. This works, but it feels like a janky hack.
function setHandler(handler) {
this.handler = handler;
return this;
}
SlashCommandBuilder.prototype.setHandler = setHandler;
Additional context
This data would be to help library builders. It shouldn't modify the toJSON()
data of any of the classes.
Please describe the problem you are having in as much detail as possible:
Include a reproducible code sample here, if possible:
According to the guide,
there's number option(not integer, floating point value)
But there's no addNumberOption method.
new SlashCommandBuilder()
(...)
.addNumberOption("number") // Property 'addNumberOption' does not exist on type 'SlashCommandBuilder'.
Further details:
Is your feature request related to a problem? Please describe.
It doesn't look very clean when we have like 10 lines of addSubcommand
, for example.
Describe the ideal solution
A new method addSubcommands
that takes an array of builders as a parameter. This could also be added for addSubcommandGroups
.
Describe alternatives you've considered
None.
Additional context
None.
Create new SlashCommandBuilder
then .addSubcommand
-> addStringOption
returns 1
instead of STRING
It will throws an error :
DiscordAPIError: Invalid Form Body
options[0].type: This field is required
Re-do same thing but with a ApplicationCommandDataResolvable const
and it will work as intended :
const command: ApplicationCommandDataResolvable = {
name: 'test',
description: 'Test',
options: [
{
name: 'subcommand',
description: 'Test subcommand',
type: 'SUB_COMMAND',
options: [
{
name: 'option',
description: 'Option',
required: true,
type: 'STRING',
},
],
},
],
};
Thank you
Edward T. Bush
const command = new SlashCommandBuilder()
.setName('test')
.setDescription('Test')
.addSubcommand((cmd) =>
cmd
.setName('subcommand')
.setDescription('Test subcommand')
.addStringOption((option) => option.setName('option').setDescription('Option').setRequired(true))
);
0.11.0
v16.13.1
Windows 10
Medium (should be fixed soon)
If we try to mix subcommands and subcommand groups at the root level of a SlashCommandBuilder, we get the following error when the call to .addSubcommand()
happens : RangeError: You cannot mix subcommands and subcommand groups at the root level.
Example :
new SlashCommandBuilder().setName("demo").setDescription("demo of the issue")
.addSubcommandGroup(option => option.setName("group").setDescription("group").addSubcommand(option => option.setName("subcommand_in_group").setDescription("Subcommand in a group")))
.addSubcommand(option => option.setName("root_subcommand").setDescription("Subcommand at the root"))
But nothing in the Discord API seems to prevent this. Actually, if we submit the command as JSON written by hand to the API or if we just comment the line that perform this check in the .addSubcommand()
method, it works juste fine and the command can be successfully registered.
The obvious solution is to remove the check for this from the method.
is createMessageComponentCollector()
available for Slash Commands? I keep getting the error
TypeError: Cannot read property 'createMessageComponentCollector' of undefined
Since the 13.4.0 Djs release, compiling to js fails due to this error:
node_modules/@discordjs/builders/dist/index.d.ts(516,5): error TS2416: Property 'toJSON' in type 'ApplicationCommandNumberOptionBase' is not assignable to the same property in base type 'ApplicationCommandOptionWithChoicesBase<number>'.
Type '() => { min_value: number; max_value: number; type: ApplicationCommandOptionType.String | ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number; ... 4 more ...; required?: boolean; } | ... 5 more ... | { ...; }' is not assignable to type '() => APIApplicationCommandOption'.
Type '{ min_value: number; max_value: number; type: ApplicationCommandOptionType.String | ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number; ... 4 more ...; required?: boolean; } | ... 5 more ... | { ...; }' is not assignable to type 'APIApplicationCommandOption'.
Type '{ min_value: number; max_value: number; type: ApplicationCommandOptionType.Subcommand | ApplicationCommandOptionType.SubcommandGroup; options?: APIApplicationCommandOption[]; name: string; description: string; required?: boolean; autocomplete?: undefined; }' is not assignable to type 'APIApplicationCommandOption'.
Type '{ min_value: number; max_value: number; type: ApplicationCommandOptionType.Subcommand | ApplicationCommandOptionType.SubcommandGroup; options?: APIApplicationCommandOption[]; name: string; description: string; required?: boolean; autocomplete?: undefined; }' is not assignable to type 'APIApplicationCommandNumericAutocompleteOptions'.
Types of property 'type' are incompatible.
Type 'ApplicationCommandOptionType.Subcommand | ApplicationCommandOptionType.SubcommandGroup' is not assignable to type 'ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number'.
Type 'ApplicationCommandOptionType.Subcommand' is not assignable to type 'ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number'.
No response
0.10.0
nodejs: 16.6.1, typescript: 4.5.4
No response
High (immediate attention needed)
This is likely already in the pipeline to be added, but there's no function to add permissions to commands at this time.
According to the guide:
The .setColor() method accepts a ColorResolvable, e.g. an integer, HEX color string, an array of RGB values or specific color strings.
However, the typescript decleration file only shows:
setColor(color: number | null): this;
The typings are not representative of what can actually be used.
No response
0.9.0
Node v17.2.0, Typescript v4.5.3
MacOS
Low (slightly annoying)
Is your feature request related to a problem? Please describe.
It would be beneficial to use the superstruct
package instead of ow
for data validation.
Describe the ideal solution
superstruct
is a more versatile and featureful library; it has a very intuitive, TypeScript-esque syntax, supports object schema validation, allows for defining custom types, and a lot more in addition to what we currently can do with ow
. I believe superstruct
would be a much better validation library overall.
Additionally, superstruct
has built-in support for TypeScript, exporting functions like is(x, struct): x is struct
and assert(x, struct): asserts x is struct
which would allow for inline inference of data types. You can also generate a type from a Schema
object very easily, reducing data duplication as you only need to write the schema, which will automatically generate a type for you:
type StructType<T> = T extends Struct<infer R> ? R : never;
const MyStruct = object({
id: Snowflake(),
something: number(),
});
export type MyType = StructType<typeof MyStruct>;
// MyType = { id: Snowflake; something: number };
Is your feature request related to a problem? Please describe.
Recently, the new context menus were introduced as a first-class way to integrate your application with Discord.
I would love to have a builder for this too as it is highly similar to the CHAT_INPUT
(slash) commands builder.
Describe the ideal solution
New UserApplicationCommandBuilder
and MessageApplicationCommandBuilder
builders.
Describe alternatives you've considered
The existing builder could be modified to suit the new types. Otherwise, users will have to make their own builders.
Calling toJSON()
from an instance of a SlashCommandBuilder
without setting required parameters (name and description) throw an error that seem from zod that isn't useful at all to understand the problem because of the size of the error and don't say what parameter is missing.
Original message:
When creating a SlashCommandBuilder and doing toJSON() zod thrown about an recived undefined and expect a string.
Step to reproduce:
SlashCommandBuilder
from @discordjs/builders
toJSON()
import { SlashCommandBuilder } from "@discordjs/builders";
new SlashCommandBuilder().setName("test").toJSON();
0.9.0
node.js v17.2.0 | Typescript 4.5.4
Windows 11
High (immediate attention needed)
SWC is a compiler for JS and TS written in Rust and is designed to be a replacement for Babel. According to their website, SWC is "20x faster than Babel on a single thread and 70x faster on four cores." Moving past marketing claims, SWC is better for this package in my opinion for a couple of reasons:
Replace all the Babel dependencies with @swc/core (compiler) and @swc/jest (jest integration). It's not hard to replace as SWC is designed to be as close to drop-in for Babel as possible.
Stick with Babel.
I am willing to PR this if it gets approved, after all, I had to do the swap anyway to test if it improved anything.
Note: the following is not relevant but required, so I wrote random values:
No response
stable
Not applicable
No response
Low (slightly annoying)
No Partials
GUILDS
No response
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.