import type { DiscordWebhookClient } from '../discord/webhook.js';
import { EmbedBuilder } from '../discord/embed-builder.js';
import type { SendEmbedParams } from './types.js';
import { ValidationError } from '../utils/errors.js';
export async function sendEmbed(
client: DiscordWebhookClient,
params: SendEmbedParams
): Promise<string> {
// Validate that at least some embed content is provided
const hasEmbedContent =
(params.title ?? false) ||
(params.description ?? false) ||
(params.image_url ?? false) ||
(params.thumbnail_url ?? false) ||
(params.author_name ?? false) ||
(params.footer_text ?? false);
if (!hasEmbedContent && !params.content) {
throw new ValidationError(
'Either message content or embed content must be provided'
);
}
// Build embed
const builder = new EmbedBuilder();
builder.fromParams(params);
const embed = builder.build();
// Send message with embed
const response = await client.send({
content: params.content,
username: params.username,
avatar_url: params.avatar_url,
embeds: [embed],
});
return `Embed sent successfully (ID: ${response.id})`;
}