({
title = '',
description = '',
color = 'primary',
fields = [],
author = null,
footer = null,
thumbnail = null,
image = null,
timestamp = false,
url = null
} = {})
| 112 | }; |
| 113 | |
| 114 | export function createEmbed({ |
| 115 | title = '', |
| 116 | description = '', |
| 117 | color = 'primary', |
| 118 | fields = [], |
| 119 | author = null, |
| 120 | footer = null, |
| 121 | thumbnail = null, |
| 122 | image = null, |
| 123 | timestamp = false, |
| 124 | url = null |
| 125 | } = {}) { |
| 126 | const embed = new EmbedBuilder(); |
| 127 | |
| 128 | if (title && typeof title === 'string' && title.length > 0) { |
| 129 | embed.setTitle(title.substring(0, 256)); |
| 130 | } |
| 131 | |
| 132 | if (description && typeof description === 'string' && description.length > 0) { |
| 133 | embed.setDescription(description.substring(0, 4096)); |
| 134 | } |
| 135 | |
| 136 | try { |
| 137 | const embedColor = getColor(color) || '#000000'; |
| 138 | embed.setColor(embedColor); |
| 139 | } catch (error) { |
| 140 | embed.setColor('#000000'); |
| 141 | } |
| 142 | |
| 143 | if (Array.isArray(fields) && fields.length > 0) { |
| 144 | const validFields = fields.filter(f => f && f.name && f.value); |
| 145 | if (validFields.length > 0) { |
| 146 | embed.addFields(validFields.slice(0, 25)); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | if (author) { |
| 151 | try { |
| 152 | if (typeof author === 'string' && author.length > 0) { |
| 153 | embed.setAuthor({ name: author.substring(0, 256) }); |
| 154 | } else if (author && typeof author.name === 'string') { |
| 155 | embed.setAuthor(author); |
| 156 | } |
| 157 | } catch (error) { |
| 158 | |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | if (footer) { |
| 163 | try { |
| 164 | if (typeof footer === 'string' && footer.length > 0) { |
| 165 | embed.setFooter({ text: footer.substring(0, 2048) }); |
| 166 | } else if (footer && typeof footer.text === 'string') { |
| 167 | embed.setFooter(footer); |
| 168 | } |
| 169 | } catch (error) { |
| 170 | |
| 171 | } |
no test coverage detected