implement select
This commit is contained in:
@@ -25,5 +25,6 @@ export type SelectInteraction = {
|
||||
id: string
|
||||
channelId: string
|
||||
customId: string
|
||||
values: string[]
|
||||
update(options: MessageOptions): Promise<void>
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
import type { Except } from "type-fest"
|
||||
import { last } from "../../helpers/last"
|
||||
import type { EmbedOptions } from "../core/components/embed-options"
|
||||
import type { SelectProps } from "../core/components/select"
|
||||
|
||||
export type MessageOptions = {
|
||||
content: string
|
||||
embeds: EmbedOptions[]
|
||||
actionRows: Array<
|
||||
Array<MessageButtonOptions | MessageLinkOptions | MessageSelectOptions>
|
||||
>
|
||||
actionRows: ActionRow[]
|
||||
}
|
||||
|
||||
type ActionRow = Array<
|
||||
MessageButtonOptions | MessageLinkOptions | MessageSelectOptions
|
||||
>
|
||||
|
||||
export type MessageButtonOptions = {
|
||||
type: "button"
|
||||
customId: string
|
||||
@@ -25,12 +30,33 @@ export type MessageLinkOptions = {
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
export type MessageSelectOptions = {
|
||||
export type MessageSelectOptions = Except<SelectProps, "children" | "value"> & {
|
||||
type: "select"
|
||||
customId: string
|
||||
options: MessageSelectOptionOptions[]
|
||||
}
|
||||
|
||||
export type MessageSelectOptionOptions = {
|
||||
label: string
|
||||
value: string
|
||||
description?: string
|
||||
emoji?: string
|
||||
}
|
||||
|
||||
export type Message = {
|
||||
edit(options: MessageOptions): Promise<void>
|
||||
disableComponents(): Promise<void>
|
||||
}
|
||||
|
||||
export function getNextActionRow(options: MessageOptions): ActionRow {
|
||||
let actionRow = last(options.actionRows)
|
||||
if (
|
||||
actionRow == undefined ||
|
||||
actionRow.length >= 5 ||
|
||||
actionRow[0]?.type === "select"
|
||||
) {
|
||||
actionRow = []
|
||||
options.actionRows.push(actionRow)
|
||||
}
|
||||
return actionRow
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user