Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

feat(SlashCommands): add attachment option #65

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions __tests__/SlashCommands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SlashCommandMentionableOption,
SlashCommandNumberOption,
SlashCommandRoleOption,
SlashCommandAttachmentOption,
SlashCommandStringOption,
SlashCommandSubcommandBuilder,
SlashCommandSubcommandGroupBuilder,
Expand All @@ -25,6 +26,7 @@ const getBooleanOption = () => new SlashCommandBooleanOption().setName('owo').se
const getUserOption = () => new SlashCommandUserOption().setName('owo').setDescription('Testing 123');
const getChannelOption = () => new SlashCommandChannelOption().setName('owo').setDescription('Testing 123');
const getRoleOption = () => new SlashCommandRoleOption().setName('owo').setDescription('Testing 123');
const getAttachmentOption = () => new SlashCommandAttachmentOption().setName('owo').setDescription('Testing 123');
const getMentionableOption = () => new SlashCommandMentionableOption().setName('owo').setDescription('Testing 123');
const getSubcommandGroup = () => new SlashCommandSubcommandGroupBuilder().setName('owo').setDescription('Testing 123');
const getSubcommand = () => new SlashCommandSubcommandBuilder().setName('owo').setDescription('Testing 123');
Expand Down Expand Up @@ -254,6 +256,8 @@ describe('Slash Commands', () => {

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

expect(() => getBuilder().addRoleOption(getAttachmentOption())).not.toThrowError();

expect(() => getBuilder().addMentionableOption(getMentionableOption())).not.toThrowError();
});

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './interactions/slashCommands/options/integer';
export * from './interactions/slashCommands/options/mentionable';
export * from './interactions/slashCommands/options/number';
export * from './interactions/slashCommands/options/role';
export * from './interactions/slashCommands/options/attachment';
export * from './interactions/slashCommands/options/string';
export * from './interactions/slashCommands/options/user';

Expand Down
10 changes: 10 additions & 0 deletions src/interactions/slashCommands/mixins/CommandOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SlashCommandIntegerOption } from '../options/integer';
import { SlashCommandMentionableOption } from '../options/mentionable';
import { SlashCommandNumberOption } from '../options/number';
import { SlashCommandRoleOption } from '../options/role';
import { SlashCommandAttachmentOption } from '../options/attachment';
import { SlashCommandStringOption } from '../options/string';
import { SlashCommandUserOption } from '../options/user';
import type { ToAPIApplicationCommandOptions } from '../SlashCommandBuilder';
Expand Down Expand Up @@ -53,6 +54,15 @@ export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
return this._sharedAddOptionMethod(input, SlashCommandRoleOption);
}

/**
* Adds an attachment option
*
* @param input A function that returns an option builder, or an already built builder
*/
public addAttachmentOption(input: SlashCommandAttachmentOption | ((builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption)) {
return this._sharedAddOptionMethod(input, SlashCommandAttachmentOption);
}

/**
* Adds a mentionable option
*
Expand Down
10 changes: 10 additions & 0 deletions src/interactions/slashCommands/options/attachment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApplicationCommandOptionType } from 'discord-api-types/v9';
import { SlashCommandOptionBase } from '../mixins/CommandOptionBase';

export class SlashCommandAttachmentOption extends SlashCommandOptionBase {
public override readonly type = ApplicationCommandOptionType.Attachment as const;

public constructor() {
super(ApplicationCommandOptionType.Attachment);
}
}