docs(builders): Add some basic documentation (#9359)

This commit is contained in:
Jiralite
2023-04-10 21:09:51 +01:00
committed by GitHub
parent c0f2dd7131
commit 8073561824
36 changed files with 690 additions and 300 deletions

View File

@@ -15,45 +15,54 @@ import {
validateDMPermission,
} from './Assertions.js';
/**
* The type a context menu command can be.
*/
export type ContextMenuCommandType = ApplicationCommandType.Message | ApplicationCommandType.User;
/**
* A builder that creates API-compatible JSON data for context menu commands.
*/
export class ContextMenuCommandBuilder {
/**
* The name of this context menu command
* The name of this command.
*/
public readonly name: string = undefined!;
/**
* The localized names for this command
* The name localizations of this command.
*/
public readonly name_localizations?: LocalizationMap;
/**
* The type of this context menu command
* The type of this command.
*/
public readonly type: ContextMenuCommandType = undefined!;
/**
* Whether the command is enabled by default when the app is added to a guild
* Whether this command is enabled by default when the application is added to a guild.
*
* @deprecated This property is deprecated and will be removed in the future.
* You should use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
* @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
*/
public readonly default_permission: boolean | undefined = undefined;
/**
* Set of permissions represented as a bit set for the command
* The set of permissions represented as a bit set for the command.
*/
public readonly default_member_permissions: Permissions | null | undefined = undefined;
/**
* Indicates whether the command is available in DMs with the application, only for globally-scoped commands.
* By default, commands are visible.
* Indicates whether the command is available in direct messages with the application.
*
* @remarks
* By default, commands are visible. This property is only for global commands.
*/
public readonly dm_permission: boolean | undefined = undefined;
/**
* Sets the name
* Sets the name of this command.
*
* @param name - The name
* @param name - The name to use
*/
public setName(name: string) {
// Assert the name matches the conditions
@@ -65,9 +74,9 @@ export class ContextMenuCommandBuilder {
}
/**
* Sets the type
* Sets the type of this command.
*
* @param type - The type
* @param type - The type to use
*/
public setType(type: ContextMenuCommandType) {
// Assert the type is valid
@@ -83,7 +92,7 @@ export class ContextMenuCommandBuilder {
*
* @remarks
* If set to `false`, you will have to later `PUT` the permissions for this command.
* @param value - Whether or not to enable this command by default
* @param value - Whether to enable this command by default
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
* @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
*/
@@ -97,7 +106,7 @@ export class ContextMenuCommandBuilder {
}
/**
* Sets the default permissions a member should have in order to run the command.
* Sets the default permissions a member should have in order to run this command.
*
* @remarks
* You can set this to `'0'` to disable the command by default.
@@ -114,10 +123,11 @@ export class ContextMenuCommandBuilder {
}
/**
* Sets if the command is available in DMs with the application, only for globally-scoped commands.
* By default, commands are visible.
* Sets if the command is available in direct messages with the application.
*
* @param enabled - If the command should be enabled in DMs
* @remarks
* By default, commands are visible. This method is only for global commands.
* @param enabled - Whether the command should be enabled in direct messages
* @see {@link https://discord.com/developers/docs/interactions/application-commands#permissions}
*/
public setDMPermission(enabled: boolean | null | undefined) {
@@ -130,10 +140,10 @@ export class ContextMenuCommandBuilder {
}
/**
* Sets a name localization
* Sets a name localization for this command.
*
* @param locale - The locale to set a description for
* @param localizedName - The localized description for the given locale
* @param locale - The locale to set
* @param localizedName - The localized name for the given `locale`
*/
public setNameLocalization(locale: LocaleString, localizedName: string | null) {
if (!this.name_localizations) {
@@ -154,9 +164,9 @@ export class ContextMenuCommandBuilder {
}
/**
* Sets the name localizations
* Sets the name localizations for this command.
*
* @param localizedNames - The dictionary of localized descriptions to set
* @param localizedNames - The object of localized names to set
*/
public setNameLocalizations(localizedNames: LocalizationMap | null) {
if (localizedNames === null) {
@@ -172,7 +182,7 @@ export class ContextMenuCommandBuilder {
}
/**
* Returns the final data that should be sent to Discord.
* Serializes this builder to API-compatible JSON data.
*
* @remarks
* This method runs validations on the data before serializing it.
@@ -186,5 +196,3 @@ export class ContextMenuCommandBuilder {
return { ...this };
}
}
export type ContextMenuCommandType = ApplicationCommandType.Message | ApplicationCommandType.User;