This code shares NASA's daily photo to a specific channel in a Discord server
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); // Import standard lib
const nasaAPIKey = process.env.NASA_API_KEY; // Your NASA API key
const channel_id = ``; // This is the channel you wish for the message to be sent in
const dailyRole = ``; // This is the role you want pinged each day
try {
let result = await lib.http.request['@1.1.7'].get({
url: `https://api.nasa.gov/planetary/apod?api_key=${nasaAPIKey}`
});
let imageURL = result.data.url;
let description = result.data.explanation;
// Retrieve the current date
const now = new Date();
await lib.discord.channels['@0.3.4'].messages.create({
channel_id: channel_id, content: `<@&${dailyRole}>`,
embeds: [
{
type: "rich",
author: {name: `NASA`, icon_url: `https://www.nasa.gov/sites/default/files/thumbnails/image/nasa-logo-web-rgb.png`},
title: `NASA Photo of the Day`,
description: description,
color: 0x0b3d91, // This is the NASA symbol's deep blue
image: {
url: imageUrl,
},
timestamp: now.toISOString(),
}
]
});
} catch (error) {
console.error(error);
}