|
1 | 1 | import { |
2 | 2 | ActionRowBuilder, |
3 | | - type ModalActionRowComponentBuilder, |
4 | 3 | ModalBuilder, |
5 | 4 | TextInputBuilder, |
6 | 5 | EmbedBuilder, |
7 | 6 | AttachmentBuilder, |
8 | | - type BufferResolvable |
| 7 | + type BufferResolvable, |
| 8 | + ButtonBuilder, |
| 9 | + ButtonStyle, |
| 10 | + type AnyComponentBuilder, |
| 11 | + type RestOrArray |
9 | 12 | } from 'discord.js' |
10 | 13 | import type { Stream } from 'node:stream' |
11 | 14 | import type { |
| 15 | + ButtonOptions, |
12 | 16 | CommandConfig, |
13 | 17 | CommandExecute, |
14 | 18 | ContextMenuCallback, |
@@ -123,6 +127,16 @@ export const definePrecondition: DefinePrecondition & |
123 | 127 | return { name, callback } |
124 | 128 | } |
125 | 129 |
|
| 130 | +export const defineActionRow = < |
| 131 | + T extends AnyComponentBuilder = AnyComponentBuilder |
| 132 | +>( |
| 133 | + ...components: RestOrArray<T> |
| 134 | +): ActionRowBuilder<T> => { |
| 135 | + const builder = new ActionRowBuilder<T>().addComponents(...components) |
| 136 | + |
| 137 | + return builder |
| 138 | +} |
| 139 | + |
126 | 140 | export const defineModal = (options: ModalOptions): ModalBuilder => { |
127 | 141 | const builder = new ModalBuilder() |
128 | 142 | .setCustomId(options.id) |
@@ -150,10 +164,7 @@ export const defineModal = (options: ModalOptions): ModalBuilder => { |
150 | 164 | if (input.required) { |
151 | 165 | inputBuilder.setRequired(input.required) |
152 | 166 | } |
153 | | - const row = |
154 | | - new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents( |
155 | | - inputBuilder |
156 | | - ) |
| 167 | + const row = defineActionRow(inputBuilder) |
157 | 168 |
|
158 | 169 | builder.addComponents(row) |
159 | 170 | } |
@@ -189,3 +200,24 @@ export const defineEmbed = (options: EmbedOptions) => { |
189 | 200 | export const defineAttachment = (args: BufferResolvable | Stream) => { |
190 | 201 | return new AttachmentBuilder(args) |
191 | 202 | } |
| 203 | + |
| 204 | +export const defineButton = (options: ButtonOptions) => { |
| 205 | + const builder = new ButtonBuilder() |
| 206 | + .setCustomId(options.id) |
| 207 | + .setStyle(options.style ? ButtonStyle[options.style] : ButtonStyle.Primary) |
| 208 | + |
| 209 | + if (options.label) { |
| 210 | + builder.setLabel(options.label) |
| 211 | + } |
| 212 | + if (options.emoji) { |
| 213 | + builder.setEmoji(options.emoji) |
| 214 | + } |
| 215 | + if (options.url) { |
| 216 | + builder.setURL(options.url) |
| 217 | + } |
| 218 | + if (options.disabled) { |
| 219 | + builder.setDisabled(options.disabled) |
| 220 | + } |
| 221 | + |
| 222 | + return builder |
| 223 | +} |
0 commit comments