A simple snippet that sends news about your provided news topic(example - crypto) & get your API key at https://newsapi.org/
// Preview - https://media.discordapp.net/attachments/1019529578210918422/1056901371569385493/image.png?width=523&height=434
// Slash Command Structure Image Link - https://media.discordapp.net/attachments/1019529578210918422/1056900594285170739/image.png?width=1020&height=430
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const axios = require('axios');
let category = context.params.event.data.options[0].value;
console.log(category);
const apiKey = `ABCDEFGHIJKLMNOPQRSTUVWXYZ`; // Get Your Own API Key At https://newsapi.org/
console.log(apiKey);
const url = `https://newsapi.org/v2/everything?q=${category}&apiKey=${apiKey}`;
console.log(url);
let response = await axios.get(url);
console.log(response.data);
let query = response.data?.articles.slice(0, 5);
if (response.data.totalResults == 0) {
return lib.discord.channels['@0.3.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Hey User What Are You Looking For? I Did'nt Find Any Data Related To Your Provided Topic?`,
});
}
for (let i = 0; i < query.length; i++) {
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: context.params.event.channel_id,
content: '',
tts: false,
components: [
{
type: 1,
components: [
{
style: 5,
label: `Article Link`,
url: `${query[i].url}`,
disabled: false,
type: 2,
},
],
},
],
embeds: [
{
type: 'rich',
title: `${query[i].title}`,
description: `${query[i].description}`,
image: {
url: `${query[i].urlToImage}`,
height: 0,
width: 0,
},
color: 0x41d43c,
footer: {
text: `Articles Published On ${query[i].publishedAt}`,
},
timestamp: `${new Date().toISOString()}`,
},
],
});
}