Giter Site home page Giter Site logo

discordjs / builders Goto Github PK

View Code? Open in Web Editor NEW
97.0 97.0 37.0 3.02 MB

A collection of builders that you can use when creating your bot.

License: Apache License 2.0

Shell 0.15% TypeScript 98.84% JavaScript 1.01%
builder builders discord discord-bot discordjs hacktoberfest

builders's People

Contributors

austr1an avatar dastormer avatar dtrombett avatar favna avatar fyko avatar icrawl avatar imrodry avatar khafradev avatar khasms avatar kyranet avatar suneettipirneni avatar superchupudev avatar vladfrangu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

builders's Issues

Validation errors

Feature

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.

Ideal solution or implementation

Revert back to the previous validator (ow) which said what exact fields and commands are causing issues

Alternative solutions or implementations

No response

Other context

image
image

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

Add Builder#toData

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.

Refs: #37 #32
Willing to submit PR

Builder for listing items in a list (for `and` and `or`)

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! :)

Channel types for channel option

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.

Context Menus

Feature

Please add context menus to the package

Ideal solution or implementation

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')	
	},
};

Builders for User and Message commands

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

Add autocomplete to options

Feature

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!

Ideal solution or implementation

I am sure a solution would be as simple as any other option!

Alternative solutions or implementations

No response

Other context

No response

Provide range option for `.addIntegerOption`

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.

Interface for SlashCommandBuilder#toJSON()

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.

Add `MessageEmbed`

I suggest we add the MessageEmbed class. I'm more than happy to take on the task.

ApplicationCommand builder

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\boilerplate\node_modules\@discordjs\builders\package.json

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

ESM TypeError: Cannot read properties of undefined (reading 'minLength')

Issue description

This issue is caused by ow, as the code below shows.

  1. Install @discordjs/[email protected]
  2. Set up an esm project
  3. Try the sample code

This issue did not occur on v0.7.x.
edit: sindresorhus/ow#215

Code sample

import { SlashCommandBuilder } from '@discordjs/builders';
new SlashCommandBuilder();

// or

import ow from 'ow';
ow.string.minLength(1); // ow.string is undefined

@discordjs/builders version

0.8.1

Node.js version

16.13.0

Operating system

Windows

Priority this issue should have

High (immediate attention needed)

Slash commands NumberOption support missing

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:

  • discord.js version: 13.1.0
  • Node.js version: 16.6.2
  • Operating system: MacOS Mojave
  • Priority this issue should have – please be realistic and elaborate if possible: high, or change the documentation if this will not be supported

Relevant client options:

  • partials: none
  • gateway intents: none
  • other: none

Ability to add command handler functions

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.

There's no addNumberOption method

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:

  • @discordjs/builders version: 0.5.0
  • Node.js version: v16.6.1
  • Priority this issue should have – please be realistic and elaborate if possible:

New methods addSubcommands and addSubcommandGroups

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.

Wrong sub/commands types

Issue description

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

Code sample

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))
    );

@discordjs/builders version

0.11.0

Node.js version

v16.13.1

Operating system

Windows 10

Priority this issue should have

Medium (should be fixed soon)

Can't mix subcommands and subcommand groups at the root level

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.

(types): ApplicationCommandNumberOptionBase is not extending base properly

Issue description

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'.

Code sample

No response

@discordjs/builders version

0.10.0

Node.js version

nodejs: 16.6.1, typescript: 4.5.4

Operating system

No response

Priority this issue should have

High (immediate attention needed)

Can't add permissions

This is likely already in the pipeline to be added, but there's no function to add permissions to commands at this time.

Types: embed.setColor() not showing ColorResolvable or number[]

Issue description

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.

Code sample

No response

@discordjs/builders version

0.9.0

Node.js version

Node v17.2.0, Typescript v4.5.3

Operating system

MacOS

Priority this issue should have

Low (slightly annoying)

Switch to superstruct for validation

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 };

🎉Context Menu Builders!

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.

Validation errors reported by zod are not useful

Issue description

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:

  1. Import SlashCommandBuilder from @discordjs/builders
  2. Create a new Builder and call toJSON()
  3. zod should throw an error that isn't useful at all

zodError.log

Code sample

import { SlashCommandBuilder } from "@discordjs/builders";
new SlashCommandBuilder().setName("test").toJSON();

@discordjs/builders version

0.9.0

Node.js version

node.js v17.2.0 | Typescript 4.5.4

Operating system

Windows 11

Priority this issue should have

High (immediate attention needed)

Replace Babel with SWC

Feature

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:

  • SWC supports much of what this repo needs out of the box, including decorator and typescript support, removing the need for a bunch of Babel plugins.
  • SWC is only 16kB, while Babel is over 1MB, not including plugins, which are hundreds of kilobytes themselves.
  • SWC is actually faster. Even setting aside examples like Next.js switching to SWC and getting up to 5x faster builds, on my machine, cold running this repo's tests resulted in 2x faster completion when using SWC, dropping times from 10.692s to 4.916s.

Ideal solution or implementation

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.

Alternative solutions or implementations

Stick with Babel.

Other context

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.

Broken link in documentation

Issue description

  1. Go to this page: https://discord.js.org/#/docs/builders/stable/typedef/AuthorOptions
  2. Click the little icon at top right
    The icon
  3. GitHub's 404 error page shows up

Note: the following is not relevant but required, so I wrote random values:
image

Code sample

No response

discord.js version

stable

Node.js version

Not applicable

Operating system

No response

Priority this issue should have

Low (slightly annoying)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

GUILDS

I have tested this issue on a development release

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.