export const useMessage = () => { const post = (url: string, message: any) => { const data = JSON.parse(JSON.stringify(message)); if (data?.embeds?.length > 0) { data.embeds = data.embeds.map((embed: any) => { if (typeof embed?.color === "string" && embed?.color?.includes("#")) { embed.color = parseInt(embed.color.replace("#", ""), 16); } return embed; }); } if (data?.buttons?.length > 0) { data.components = [ { type: 1, components: data.buttons.map((button: any) => { const { style, label, emoji, url, disabled } = button; return { type: 2, style, label, emoji, url, disabled, }; }), }, ]; } fetch(url, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }) .then((res) => { console.log(res); }) .catch((err) => { console.log(err); }); }; return { post }; };