-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (45 loc) · 1.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
client.once("ready", async () => {
const data = [
{
name: "news",
description: "ニュースを表示します",
}
];
await client.application.commands.set(data);
console.log("set");
});
client.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) {
return;
}
if (interaction.commandName === "news") {
const fetch = require("node-fetch");
const data = await fetch(
`https://newsapi.org/v2/top-headlines?country=jp&apiKey=${process.env.news}`
)
.then((res) => res.json())
.catch(() => {});
await interaction.reply({
embeds: [
{
color: "BLUE",
timestamp: new Date(),
fields: [
{
name: data.articles[0].title,
value: data.articles[0].url + "\n" + data.articles[0].description,
},
{
name: data.articles[1].title,
value: data.articles[1].url + "\n" + data.articles[1].description,
},
{
name: data.articles[2].title,
value: data.articles[2].url + "\n" + data.articles[2].description,
},
],
},
],
});
}
})