mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
types: cleanup *Data type definitions (#7716)
This commit is contained in:
32
packages/discord.js/typings/index.d.ts
vendored
32
packages/discord.js/typings/index.d.ts
vendored
@@ -216,27 +216,29 @@ export class Activity {
|
|||||||
export type ActivityFlagsString = keyof typeof ActivityFlags;
|
export type ActivityFlagsString = keyof typeof ActivityFlags;
|
||||||
|
|
||||||
export interface BaseComponentData {
|
export interface BaseComponentData {
|
||||||
type?: ComponentType;
|
type: ComponentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MessageActionRowComponentData = ButtonComponentData | SelectMenuComponentData;
|
export type MessageActionRowComponentData =
|
||||||
|
| JSONEncodable<APIMessageActionRowComponent>
|
||||||
|
| ButtonComponentData
|
||||||
|
| SelectMenuComponentData;
|
||||||
|
|
||||||
export type ModalActionRowComponentData = TextInputComponentData;
|
export type ModalActionRowComponentData = JSONEncodable<APIModalActionRowComponent> | TextInputComponentData;
|
||||||
|
|
||||||
export type ActionRowComponentData = MessageActionRowComponentData | ModalActionRowComponentData;
|
export type ActionRowComponentData = MessageActionRowComponentData | ModalActionRowComponentData;
|
||||||
|
|
||||||
export type ActionRowComponent = MessageActionRowComponent | ModalActionRowComponent;
|
export type ActionRowComponent = MessageActionRowComponent | ModalActionRowComponent;
|
||||||
|
|
||||||
export type ActionRowComponentBuilder = MessageActionRowComponentBuilder | ModalActionRowComponentBuilder;
|
export interface ActionRowData<T extends JSONEncodable<APIActionRowComponentTypes> | ActionRowComponentData>
|
||||||
|
extends BaseComponentData {
|
||||||
export interface ActionRowData<T extends ActionRowComponentBuilder | ActionRowComponentData> extends BaseComponentData {
|
|
||||||
components: T[];
|
components: T[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ActionRowBuilder<T extends AnyComponentBuilder = AnyComponentBuilder> extends BuilderActionRow<T> {
|
export class ActionRowBuilder<T extends AnyComponentBuilder = AnyComponentBuilder> extends BuilderActionRow<T> {
|
||||||
constructor(
|
constructor(
|
||||||
data?: Partial<
|
data?: Partial<
|
||||||
| ActionRowData<ActionRowComponentData | ActionRowComponentBuilder>
|
| ActionRowData<ActionRowComponentData | JSONEncodable<APIActionRowComponentTypes>>
|
||||||
| APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>
|
| APIActionRowComponent<APIMessageActionRowComponent | APIModalActionRowComponent>
|
||||||
>,
|
>,
|
||||||
);
|
);
|
||||||
@@ -587,7 +589,7 @@ export class ButtonComponent extends Component<APIButtonComponent> {
|
|||||||
export type ComponentEmojiResolvable = APIMessageComponentEmoji | string;
|
export type ComponentEmojiResolvable = APIMessageComponentEmoji | string;
|
||||||
|
|
||||||
export class ButtonBuilder extends BuilderButtonComponent {
|
export class ButtonBuilder extends BuilderButtonComponent {
|
||||||
public constructor(data?: ButtonComponentData | (Omit<APIButtonComponent, 'type'> & { type?: ComponentType.Button }));
|
public constructor(data?: Partial<ButtonComponentData> | Partial<APIButtonComponent>);
|
||||||
public static from(other: JSONEncodable<APIButtonComponent> | APIButtonComponent): ButtonBuilder;
|
public static from(other: JSONEncodable<APIButtonComponent> | APIButtonComponent): ButtonBuilder;
|
||||||
public override setEmoji(emoji: ComponentEmojiResolvable): this;
|
public override setEmoji(emoji: ComponentEmojiResolvable): this;
|
||||||
}
|
}
|
||||||
@@ -4736,9 +4738,9 @@ export interface MakeErrorOptions {
|
|||||||
stack: string;
|
stack: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ActionRowComponentOptions =
|
export type MemberMention = UserMention | `<@!${Snowflake}>`;
|
||||||
| (Required<BaseComponentData> & ButtonComponentData)
|
|
||||||
| (Required<BaseComponentData> & SelectMenuComponentData);
|
export type ActionRowComponentOptions = ButtonComponentData | SelectMenuComponentData;
|
||||||
|
|
||||||
export type MessageActionRowComponentResolvable = MessageActionRowComponent | ActionRowComponentOptions;
|
export type MessageActionRowComponentResolvable = MessageActionRowComponent | ActionRowComponentOptions;
|
||||||
|
|
||||||
@@ -4748,6 +4750,7 @@ export interface MessageActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface BaseButtonComponentData extends BaseComponentData {
|
export interface BaseButtonComponentData extends BaseComponentData {
|
||||||
|
style: ButtonStyle;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
emoji?: ComponentEmojiResolvable;
|
emoji?: ComponentEmojiResolvable;
|
||||||
label?: string;
|
label?: string;
|
||||||
@@ -4795,7 +4798,8 @@ export interface MessageEditOptions {
|
|||||||
allowedMentions?: MessageMentionOptions;
|
allowedMentions?: MessageMentionOptions;
|
||||||
components?: (
|
components?: (
|
||||||
| JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>>
|
| JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>>
|
||||||
| (Required<BaseComponentData> & ActionRowData<MessageActionRowComponentData | MessageActionRowComponentBuilder>)
|
| ActionRow<MessageActionRowComponent>
|
||||||
|
| ActionRowData<MessageActionRowComponentData | MessageActionRowComponentBuilder>
|
||||||
| APIActionRowComponent<APIMessageActionRowComponent>
|
| APIActionRowComponent<APIMessageActionRowComponent>
|
||||||
)[];
|
)[];
|
||||||
}
|
}
|
||||||
@@ -4836,7 +4840,7 @@ export interface MessageOptions {
|
|||||||
embeds?: (JSONEncodable<APIEmbed> | APIEmbed)[];
|
embeds?: (JSONEncodable<APIEmbed> | APIEmbed)[];
|
||||||
components?: (
|
components?: (
|
||||||
| JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>>
|
| JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>>
|
||||||
| (Required<BaseComponentData> & ActionRowData<MessageActionRowComponentData | MessageActionRowComponentBuilder>)
|
| ActionRowData<MessageActionRowComponentData | MessageActionRowComponentBuilder>
|
||||||
| APIActionRowComponent<APIMessageActionRowComponent>
|
| APIActionRowComponent<APIMessageActionRowComponent>
|
||||||
)[];
|
)[];
|
||||||
allowedMentions?: MessageMentionOptions;
|
allowedMentions?: MessageMentionOptions;
|
||||||
@@ -4864,6 +4868,7 @@ export interface MessageReference {
|
|||||||
export type MessageResolvable = Message | Snowflake;
|
export type MessageResolvable = Message | Snowflake;
|
||||||
|
|
||||||
export interface SelectMenuComponentData extends BaseComponentData {
|
export interface SelectMenuComponentData extends BaseComponentData {
|
||||||
|
type: ComponentType.SelectMenu;
|
||||||
customId: string;
|
customId: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
maxValues?: number;
|
maxValues?: number;
|
||||||
@@ -4889,6 +4894,7 @@ export interface SelectMenuComponentOptionData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface TextInputComponentData extends BaseComponentData {
|
export interface TextInputComponentData extends BaseComponentData {
|
||||||
|
type: ComponentType.TextInput;
|
||||||
customId: string;
|
customId: string;
|
||||||
style: TextInputStyle;
|
style: TextInputStyle;
|
||||||
label: string;
|
label: string;
|
||||||
|
|||||||
@@ -526,6 +526,34 @@ client.on('guildCreate', async g => {
|
|||||||
const channel = g.channels.cache.random();
|
const channel = g.channels.cache.random();
|
||||||
if (!channel) return;
|
if (!channel) return;
|
||||||
|
|
||||||
|
if (channel.isText()) {
|
||||||
|
const row: ActionRowData<MessageActionRowComponentData> = {
|
||||||
|
type: ComponentType.ActionRow,
|
||||||
|
components: [
|
||||||
|
new ButtonBuilder(),
|
||||||
|
{ type: ComponentType.Button, style: ButtonStyle.Primary, label: 'string', customId: 'foo' },
|
||||||
|
{ type: ComponentType.Button, style: ButtonStyle.Link, label: 'test', url: 'test' },
|
||||||
|
{ type: ComponentType.SelectMenu, customId: 'foo' },
|
||||||
|
new SelectMenuBuilder(),
|
||||||
|
// @ts-expect-error
|
||||||
|
{ type: ComponentType.TextInput, style: TextInputStyle.Paragraph, customId: 'foo', label: 'test' },
|
||||||
|
// @ts-expect-error
|
||||||
|
new TextInputBuilder(),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const row2 = new ActionRowBuilder<MessageActionRowComponentBuilder>({
|
||||||
|
type: ComponentType.ActionRow,
|
||||||
|
components: [
|
||||||
|
{ type: ComponentType.Button, style: ButtonStyle.Primary, label: 'string', customId: 'foo' },
|
||||||
|
{ type: ComponentType.Button, style: ButtonStyle.Link, label: 'test', url: 'test' },
|
||||||
|
{ type: ComponentType.SelectMenu, customId: 'foo' },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
channel.send({ components: [row, row2] });
|
||||||
|
}
|
||||||
|
|
||||||
if (channel.isThread()) {
|
if (channel.isThread()) {
|
||||||
const fetchedMember = await channel.members.fetch({ member: '12345678' });
|
const fetchedMember = await channel.members.fetch({ member: '12345678' });
|
||||||
expectType<ThreadMember>(fetchedMember);
|
expectType<ThreadMember>(fetchedMember);
|
||||||
@@ -738,7 +766,7 @@ client.on('messageCreate', async message => {
|
|||||||
|
|
||||||
// Check that both builders and builder data can be sent in messages
|
// Check that both builders and builder data can be sent in messages
|
||||||
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>();
|
const row = new ActionRowBuilder<MessageActionRowComponentBuilder>();
|
||||||
const buttonsRow = {
|
const buttonsRow: ActionRowData<MessageActionRowComponentData> = {
|
||||||
type: ComponentType.ActionRow,
|
type: ComponentType.ActionRow,
|
||||||
components: [
|
components: [
|
||||||
new ButtonBuilder(),
|
new ButtonBuilder(),
|
||||||
@@ -747,12 +775,12 @@ client.on('messageCreate', async message => {
|
|||||||
{
|
{
|
||||||
type: ComponentType.Button,
|
type: ComponentType.Button,
|
||||||
label: 'another test',
|
label: 'another test',
|
||||||
style: ButtonStyle.Link as const,
|
style: ButtonStyle.Link,
|
||||||
url: 'https://discord.js.org',
|
url: 'https://discord.js.org',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
const selectsRow = {
|
const selectsRow: ActionRowData<MessageActionRowComponentData> = {
|
||||||
type: ComponentType.ActionRow,
|
type: ComponentType.ActionRow,
|
||||||
components: [
|
components: [
|
||||||
new SelectMenuBuilder(),
|
new SelectMenuBuilder(),
|
||||||
@@ -765,6 +793,7 @@ client.on('messageCreate', async message => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildersEmbed = new UnsafeEmbedBuilder();
|
const buildersEmbed = new UnsafeEmbedBuilder();
|
||||||
const embedData = { description: 'test', color: 0xff0000 };
|
const embedData = { description: 'test', color: 0xff0000 };
|
||||||
channel.send({ components: [row, buttonsRow, selectsRow], embeds: [embed, buildersEmbed, embedData] });
|
channel.send({ components: [row, buttonsRow, selectsRow], embeds: [embed, buildersEmbed, embedData] });
|
||||||
|
|||||||
Reference in New Issue
Block a user