(customId, label, style = 'primary', emoji = null, disabled = false)
| 60 | } |
| 61 | |
| 62 | export function createButton(customId, label, style = 'primary', emoji = null, disabled = false) { |
| 63 | |
| 64 | if (!customId || typeof customId !== 'string' || customId.length === 0) { |
| 65 | throw new Error('customId must be a non-empty string'); |
| 66 | } |
| 67 | if (!label || typeof label !== 'string' || label.length === 0) { |
| 68 | throw new Error('label must be a non-empty string'); |
| 69 | } |
| 70 | |
| 71 | const validCustomId = customId.substring(0, 100); |
| 72 | const validLabel = label.substring(0, 80); |
| 73 | |
| 74 | const normalizedStyle = style.charAt(0).toUpperCase() + style.slice(1).toLowerCase(); |
| 75 | const buttonStyle = ButtonStyle[normalizedStyle] || ButtonStyle.Primary; |
| 76 | |
| 77 | const button = new ButtonBuilder() |
| 78 | .setCustomId(validCustomId) |
| 79 | .setLabel(validLabel) |
| 80 | .setStyle(buttonStyle) |
| 81 | .setDisabled(disabled === true); |
| 82 | |
| 83 | if (emoji && typeof emoji === 'string' && emoji.length > 0) { |
| 84 | try { |
| 85 | button.setEmoji(emoji); |
| 86 | } catch (error) { |
| 87 | |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | return button; |
| 92 | } |
| 93 | |
| 94 | export function createLinkButton(label, url, emoji = null) { |
| 95 |
no outgoing calls
no test coverage detected