Skip to content

feat(ContextMenu) - Support Context Menus #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 15 additions & 1 deletion src/builders/CommandBuilders.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import {
ApplicationCommandTypes,
ApplicationCommandOption,
ApplicationCommandOptionChoice,
ApplicationCommandOptionType,
PartialApplicationCommand,
PartialApplicationCommand
} from "../structures";

export class CommandBuilder {
private name: string;
private description: string;
private options: ApplicationCommandOption[];
private type: ApplicationCommandTypes;

constructor() {
this.options = [];
this.type = 1;
}

public setName(name: string): CommandBuilder {
Expand All @@ -23,6 +26,11 @@ export class CommandBuilder {
}

public setDescription(description: string): CommandBuilder {
// User and Message commands (Context Menu commands) does not support descriptions
if (this.type !== 1) {
throw new Error("A context menu command cannot have a description");
}

if (description.length < 1 || description.length > 100) {
throw new Error(
"Command descriptions must be between 1 and 100 characters"
Expand All @@ -31,6 +39,11 @@ export class CommandBuilder {
this.description = description;
return this;
}

public setType(type: ApplicationCommandTypes): CommandBuilder {
this.type = type;
return this;
}

public addOption(option: ApplicationCommandOption): CommandBuilder {
this.options.push(option);
Expand All @@ -42,6 +55,7 @@ export class CommandBuilder {
name: this.name,
description: this.description,
options: this.options,
type: this.type
};
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/structures/ApplicationCommand.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { ApplicationCommandOption } from "./ApplicationCommandOptions";
import { Snowflake } from "./Snowflake";

export enum ApplicationCommandTypes {
CHAT_INPUT = 1,
USER = 2,
MESSAGE = 3
}

export type ApplicationCommand = {
id: Snowflake;
type: ApplicationCommandTypes;
application_id: Snowflake;
name: string;
description: string;
Expand All @@ -13,4 +20,5 @@ export type PartialApplicationCommand = {
name: string;
description: string;
options?: ApplicationCommandOption[];
type: ApplicationCommandTypes;
};