Skip to content

Commit ae0f35f

Browse files
feat(builders): add attachment command option type (#7203)
1 parent 0af9bc8 commit ae0f35f

File tree

15 files changed

+751
-685
lines changed

15 files changed

+751
-685
lines changed

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
},
3939
"homepage": "https://discord.js.org",
4040
"devDependencies": {
41-
"@commitlint/cli": "^16.1.0",
42-
"@commitlint/config-angular": "^16.0.0",
41+
"@commitlint/cli": "^16.2.1",
42+
"@commitlint/config-angular": "^16.2.1",
4343
"@favware/npm-deprecate": "^1.0.4",
4444
"conventional-changelog-cli": "^2.2.2",
4545
"husky": "^7.0.4",

Diff for: packages/builders/__tests__/components/actionRow.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { APIActionRowComponent, ButtonStyle, ComponentType } from 'discord-api-types/v9';
1+
import { APIActionRowComponent, APIMessageComponent, ButtonStyle, ComponentType } from 'discord-api-types/v9';
22
import { ActionRow, ButtonComponent, createComponent, SelectMenuComponent, SelectMenuOption } from '../../src';
33

44
describe('Action Row Components', () => {
@@ -9,7 +9,7 @@ describe('Action Row Components', () => {
99
});
1010

1111
test('GIVEN valid JSON input THEN valid JSON output is given', () => {
12-
const actionRowData: APIActionRowComponent = {
12+
const actionRowData: APIActionRowComponent<APIMessageComponent> = {
1313
type: ComponentType.ActionRow,
1414
components: [
1515
{
@@ -45,7 +45,7 @@ describe('Action Row Components', () => {
4545
expect(() => createComponent({ type: 42, components: [] })).toThrowError();
4646
});
4747
test('GIVEN valid builder options THEN valid JSON output is given', () => {
48-
const rowWithButtonData: APIActionRowComponent = {
48+
const rowWithButtonData: APIActionRowComponent<APIMessageComponent> = {
4949
type: ComponentType.ActionRow,
5050
components: [
5151
{
@@ -57,7 +57,7 @@ describe('Action Row Components', () => {
5757
],
5858
};
5959

60-
const rowWithSelectMenuData: APIActionRowComponent = {
60+
const rowWithSelectMenuData: APIActionRowComponent<APIMessageComponent> = {
6161
type: ComponentType.ActionRow,
6262
components: [
6363
{

Diff for: packages/builders/__tests__/interactions/SlashCommands/SlashCommands.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
SlashCommandMentionableOption,
99
SlashCommandNumberOption,
1010
SlashCommandRoleOption,
11+
SlashCommandAttachmentOption,
1112
SlashCommandStringOption,
1213
SlashCommandSubcommandBuilder,
1314
SlashCommandSubcommandGroupBuilder,
@@ -25,6 +26,7 @@ const getBooleanOption = () => new SlashCommandBooleanOption().setName('owo').se
2526
const getUserOption = () => new SlashCommandUserOption().setName('owo').setDescription('Testing 123');
2627
const getChannelOption = () => new SlashCommandChannelOption().setName('owo').setDescription('Testing 123');
2728
const getRoleOption = () => new SlashCommandRoleOption().setName('owo').setDescription('Testing 123');
29+
const getAttachmentOption = () => new SlashCommandAttachmentOption().setName('owo').setDescription('Testing 123');
2830
const getMentionableOption = () => new SlashCommandMentionableOption().setName('owo').setDescription('Testing 123');
2931
const getSubcommandGroup = () => new SlashCommandSubcommandGroupBuilder().setName('owo').setDescription('Testing 123');
3032
const getSubcommand = () => new SlashCommandSubcommandBuilder().setName('owo').setDescription('Testing 123');
@@ -286,6 +288,8 @@ describe('Slash Commands', () => {
286288

287289
expect(() => getBuilder().addRoleOption(getRoleOption())).not.toThrowError();
288290

291+
expect(() => getBuilder().addAttachmentOption(getAttachmentOption())).not.toThrowError();
292+
289293
expect(() => getBuilder().addMentionableOption(getMentionableOption())).not.toThrowError();
290294
});
291295

Diff for: packages/builders/package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@
5252
"homepage": "https://discord.js.org",
5353
"dependencies": {
5454
"@sindresorhus/is": "^4.4.0",
55-
"discord-api-types": "^0.26.1",
55+
"discord-api-types": "^0.27.0",
5656
"ts-mixer": "^6.0.0",
5757
"tslib": "^2.3.1",
5858
"zod": "^3.11.6"
5959
},
6060
"devDependencies": {
61-
"@babel/core": "^7.17.0",
62-
"@babel/plugin-proposal-decorators": "^7.17.0",
61+
"@babel/core": "^7.17.2",
62+
"@babel/plugin-proposal-decorators": "^7.17.2",
6363
"@babel/preset-env": "^7.16.11",
64-
"@babel/preset-typescript": "^7.16.5",
64+
"@babel/preset-typescript": "^7.16.7",
6565
"@discordjs/ts-docgen": "^0.3.4",
66-
"@types/jest": "^27.0.3",
67-
"@types/node": "^16.11.6",
68-
"@typescript-eslint/eslint-plugin": "^5.10.2",
69-
"@typescript-eslint/parser": "^5.10.2",
66+
"@types/jest": "^27.4.0",
67+
"@types/node": "^16.11.24",
68+
"@typescript-eslint/eslint-plugin": "^5.11.0",
69+
"@typescript-eslint/parser": "^5.11.0",
7070
"babel-plugin-transform-typescript-metadata": "^0.3.2",
71-
"eslint": "^8.8.0",
71+
"eslint": "^8.9.0",
7272
"eslint-config-marine": "^9.3.2",
7373
"eslint-config-prettier": "^8.3.0",
7474
"eslint-plugin-prettier": "^4.0.0",
75-
"jest": "^27.4.7",
75+
"jest": "^27.5.1",
7676
"prettier": "^2.5.1",
7777
"tsup": "^5.11.13",
7878
"typedoc": "^0.22.11",

Diff for: packages/builders/src/components/ActionRow.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type APIActionRowComponent, ComponentType } from 'discord-api-types/v9';
1+
import { type APIActionRowComponent, ComponentType, APIMessageComponent } from 'discord-api-types/v9';
22
import type { ButtonComponent, SelectMenuComponent } from '..';
33
import { Component } from './Component';
44
import { createComponent } from './Components';
@@ -12,11 +12,11 @@ export type ActionRowComponent = ButtonComponent | SelectMenuComponent;
1212
* Represents an action row component
1313
*/
1414
export class ActionRow<T extends ActionRowComponent = ActionRowComponent> extends Component<
15-
Omit<Partial<APIActionRowComponent> & { type: ComponentType.ActionRow }, 'components'>
15+
Omit<Partial<APIActionRowComponent<APIMessageComponent>> & { type: ComponentType.ActionRow }, 'components'>
1616
> {
1717
public readonly components: T[];
1818

19-
public constructor({ components, ...data }: Partial<APIActionRowComponent> = {}) {
19+
public constructor({ components, ...data }: Partial<APIActionRowComponent<APIMessageComponent>> = {}) {
2020
super({ type: ComponentType.ActionRow, ...data });
2121
this.components = (components?.map((c) => createComponent(c)) ?? []) as T[];
2222
}
@@ -40,7 +40,7 @@ export class ActionRow<T extends ActionRowComponent = ActionRowComponent> extend
4040
return this;
4141
}
4242

43-
public toJSON(): APIActionRowComponent {
43+
public toJSON(): APIActionRowComponent<APIMessageComponent> {
4444
return {
4545
...this.data,
4646
components: this.components.map((component) => component.toJSON()),

Diff for: packages/builders/src/components/Component.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { JSONEncodable } from '../util/jsonEncodable';
2-
import type { APIBaseMessageComponent, APIMessageComponent, ComponentType } from 'discord-api-types/v9';
2+
import type { APIBaseComponent, APIMessageComponent, ComponentType } from 'discord-api-types/v9';
33

44
/**
55
* Represents a discord component
66
*/
77
export abstract class Component<
8-
DataType extends Partial<APIBaseMessageComponent<ComponentType>> & {
8+
DataType extends Partial<APIBaseComponent<ComponentType>> & {
99
type: ComponentType;
10-
} = APIBaseMessageComponent<ComponentType>,
10+
} = APIBaseComponent<ComponentType>,
1111
> implements JSONEncodable<APIMessageComponent>
1212
{
1313
/**

Diff for: packages/builders/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export * from './interactions/slashCommands/options/integer';
2323
export * from './interactions/slashCommands/options/mentionable';
2424
export * from './interactions/slashCommands/options/number';
2525
export * from './interactions/slashCommands/options/role';
26+
export * from './interactions/slashCommands/options/attachment';
2627
export * from './interactions/slashCommands/options/string';
2728
export * from './interactions/slashCommands/options/user';
2829

Diff for: packages/builders/src/interactions/slashCommands/mixins/SharedSlashCommandOptions.ts

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SlashCommandIntegerOption } from '../options/integer';
66
import { SlashCommandMentionableOption } from '../options/mentionable';
77
import { SlashCommandNumberOption } from '../options/number';
88
import { SlashCommandRoleOption } from '../options/role';
9+
import { SlashCommandAttachmentOption } from '../options/attachment';
910
import { SlashCommandStringOption } from '../options/string';
1011
import { SlashCommandUserOption } from '../options/user';
1112
import type { ToAPIApplicationCommandOptions } from '../SlashCommandBuilder';
@@ -53,6 +54,17 @@ export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
5354
return this._sharedAddOptionMethod(input, SlashCommandRoleOption);
5455
}
5556

57+
/**
58+
* Adds an attachment option
59+
*
60+
* @param input A function that returns an option builder, or an already built builder
61+
*/
62+
public addAttachmentOption(
63+
input: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption),
64+
) {
65+
return this._sharedAddOptionMethod(input, SlashCommandAttachmentOption);
66+
}
67+
5668
/**
5769
* Adds a mentionable option
5870
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { APIApplicationCommandAttachmentOption, ApplicationCommandOptionType } from 'discord-api-types/v9';
2+
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase';
3+
4+
export class SlashCommandAttachmentOption extends ApplicationCommandOptionBase {
5+
public override readonly type = ApplicationCommandOptionType.Attachment as const;
6+
7+
public toJSON(): APIApplicationCommandAttachmentOption {
8+
this.runRequiredValidations();
9+
10+
return { ...this };
11+
}
12+
}

Diff for: packages/collection/package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@
4747
},
4848
"homepage": "https://discord.js.org",
4949
"devDependencies": {
50-
"@babel/core": "^7.17.0",
50+
"@babel/core": "^7.17.2",
5151
"@babel/preset-env": "^7.16.11",
52-
"@babel/preset-typescript": "^7.16.5",
52+
"@babel/preset-typescript": "^7.16.7",
5353
"@discordjs/ts-docgen": "^0.3.4",
54-
"@types/jest": "^27.0.3",
55-
"@types/node": "^16.11.6",
56-
"@typescript-eslint/eslint-plugin": "^5.10.2",
57-
"@typescript-eslint/parser": "^5.10.2",
58-
"eslint": "^8.8.0",
54+
"@types/jest": "^27.4.0",
55+
"@types/node": "^16.11.24",
56+
"@typescript-eslint/eslint-plugin": "^5.11.0",
57+
"@typescript-eslint/parser": "^5.11.0",
58+
"eslint": "^8.9.0",
5959
"eslint-config-marine": "^9.3.2",
6060
"eslint-config-prettier": "^8.3.0",
6161
"eslint-plugin-prettier": "^4.0.0",
62-
"jest": "^27.4.7",
62+
"jest": "^27.5.1",
6363
"prettier": "^2.5.1",
6464
"tsup": "^5.11.13",
6565
"typedoc": "^0.22.11",

Diff for: packages/discord.js/package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,23 @@
5252
"@discordjs/rest": "workspace:^",
5353
"@sapphire/snowflake": "^3.1.0",
5454
"@types/ws": "^8.2.2",
55-
"discord-api-types": "^0.26.1",
55+
"discord-api-types": "^0.27.0",
5656
"node-fetch": "^2.6.7",
57-
"ws": "^8.4.2"
57+
"ws": "^8.5.0"
5858
},
5959
"devDependencies": {
6060
"@discordjs/docgen": "^0.11.0",
61-
"@types/node": "^16.11.12",
61+
"@types/node": "^16.11.24",
6262
"dtslint": "^4.2.1",
63-
"eslint": "^8.8.0",
63+
"eslint": "^8.9.0",
6464
"eslint-config-prettier": "^8.3.0",
6565
"eslint-plugin-import": "^2.25.4",
6666
"eslint-plugin-prettier": "^4.0.0",
6767
"husky": "^7.0.4",
6868
"is-ci": "^3.0.1",
69-
"jest": "^27.4.7",
69+
"jest": "^27.5.1",
7070
"prettier": "^2.5.1",
71-
"tsd": "^0.19.0",
71+
"tsd": "^0.19.1",
7272
"tslint": "^6.1.3",
7373
"typescript": "^4.5.5"
7474
},

Diff for: packages/discord.js/typings/index.d.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export interface ActionRowData extends BaseComponentData {
201201
}
202202

203203
export class ActionRow<T extends ActionRowComponent = ActionRowComponent> extends BuilderActionRow<T> {
204-
constructor(data?: ActionRowData | APIActionRowComponent);
204+
constructor(data?: ActionRowData | APIActionRowComponent<APIMessageComponent>);
205205
}
206206

207207
export class ActivityFlagsBitField extends BitField<ActivityFlagsString> {
@@ -1500,6 +1500,7 @@ export interface MappedInteractionTypes<Cached extends boolean = boolean> {
15001500
[ComponentType.Button]: ButtonInteraction<WrapBooleanCache<Cached>>;
15011501
[ComponentType.SelectMenu]: SelectMenuInteraction<WrapBooleanCache<Cached>>;
15021502
[ComponentType.ActionRow]: MessageComponentInteraction<WrapBooleanCache<Cached>>;
1503+
[ComponentType.TextInput]: never;
15031504
}
15041505

15051506
export class Message<Cached extends boolean = boolean> extends Base {
@@ -1615,9 +1616,9 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
16151616
public readonly component: CacheTypeReducer<
16161617
Cached,
16171618
ActionRowComponent,
1618-
Exclude<APIMessageComponent, APIActionRowComponent>,
1619-
ActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent>,
1620-
ActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent>
1619+
Exclude<APIMessageComponent, APIActionRowComponent<APIMessageComponent>>,
1620+
ActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent<APIMessageComponent>>,
1621+
ActionRowComponent | Exclude<APIMessageComponent, APIActionRowComponent<APIMessageComponent>>
16211622
>;
16221623
public componentType: Exclude<ComponentType, ComponentType.ActionRow>;
16231624
public customId: string;

Diff for: packages/rest/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,27 @@
5353
"@sapphire/async-queue": "^1.2.0",
5454
"@sapphire/snowflake": "^3.1.0",
5555
"@types/node-fetch": "^2.5.12",
56-
"discord-api-types": "^0.26.1",
56+
"discord-api-types": "^0.27.0",
5757
"form-data": "^4.0.0",
5858
"node-fetch": "^2.6.7",
5959
"tslib": "^2.3.1"
6060
},
6161
"devDependencies": {
62-
"@babel/core": "^7.17.0",
63-
"@babel/plugin-proposal-decorators": "^7.17.0",
62+
"@babel/core": "^7.17.2",
63+
"@babel/plugin-proposal-decorators": "^7.17.2",
6464
"@babel/preset-env": "^7.16.11",
6565
"@babel/preset-typescript": "^7.16.7",
6666
"@discordjs/ts-docgen": "^0.3.4",
6767
"@types/jest": "^27.4.0",
68-
"@typescript-eslint/eslint-plugin": "^5.10.2",
69-
"@typescript-eslint/parser": "^5.10.2",
68+
"@typescript-eslint/eslint-plugin": "^5.11.0",
69+
"@typescript-eslint/parser": "^5.11.0",
7070
"babel-plugin-const-enum": "^1.2.0",
7171
"babel-plugin-transform-typescript-metadata": "^0.3.2",
72-
"eslint": "^8.8.0",
72+
"eslint": "^8.9.0",
7373
"eslint-config-marine": "^9.3.2",
7474
"eslint-config-prettier": "^8.3.0",
7575
"eslint-plugin-prettier": "^4.0.0",
76-
"jest": "^27.4.7",
76+
"jest": "^27.5.1",
7777
"nock": "^13.2.4",
7878
"prettier": "^2.5.1",
7979
"tsup": "^5.11.13",

Diff for: packages/voice/package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,30 @@
4949
},
5050
"homepage": "https://discord.js.org",
5151
"dependencies": {
52-
"@types/ws": "^8.2.0",
53-
"discord-api-types": "^0.26.1",
52+
"@types/ws": "^8.2.2",
53+
"discord-api-types": "^0.27.0",
5454
"prism-media": "^1.3.2",
5555
"tiny-typed-emitter": "^2.1.0",
5656
"tslib": "^2.3.1",
57-
"ws": "^8.4.2"
57+
"ws": "^8.5.0"
5858
},
5959
"devDependencies": {
60-
"@babel/core": "^7.17.0",
60+
"@babel/core": "^7.17.2",
6161
"@babel/preset-env": "^7.16.11",
62-
"@babel/preset-typescript": "^7.16.0",
63-
"@discordjs/ts-docgen": "^0.3.2",
64-
"@types/jest": "^27.0.2",
65-
"@types/node": "^16.11.7",
66-
"@typescript-eslint/eslint-plugin": "^5.10.2",
67-
"@typescript-eslint/parser": "^5.10.2",
68-
"eslint": "^8.8.0",
62+
"@babel/preset-typescript": "^7.16.7",
63+
"@discordjs/ts-docgen": "^0.3.4",
64+
"@types/jest": "^27.4.0",
65+
"@types/node": "^16.11.24",
66+
"@typescript-eslint/eslint-plugin": "^5.11.0",
67+
"@typescript-eslint/parser": "^5.11.0",
68+
"eslint": "^8.9.0",
6969
"eslint-config-marine": "^9.3.2",
7070
"eslint-config-prettier": "^8.3.0",
7171
"eslint-plugin-prettier": "^4.0.0",
72-
"jest": "^27.4.7",
72+
"jest": "^27.5.1",
7373
"jest-websocket-mock": "^2.3.0",
7474
"mock-socket": "^9.1.2",
75-
"prettier": "^2.4.1",
75+
"prettier": "^2.5.1",
7676
"tsup": "^5.11.13",
7777
"tweetnacl": "^1.0.3",
7878
"typedoc": "^0.22.11",

0 commit comments

Comments
 (0)