MCPcopy Create free account
hub / github.com/codebymitch/TitanBot / createButton

Function createButton

src/utils/components.js:62–92  ·  view source on GitHub ↗
(customId, label, style = 'primary', emoji = null, disabled = false)

Source from the content-addressed store, hash-verified

60}
61
62export 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
94export function createLinkButton(label, url, emoji = null) {
95

Callers 3

createAllCommandsMenuFunction · 0.90
createButtonRowFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected