-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (36 loc) · 1.08 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
require("dotenv").config();
const { Client, Intents } = require("discord.js");
const rp = require("request-promise");
const { DISCORD_BOT_TOKEN, COIN_ID } = process.env;
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const COIN_CURRENCY = "BRL";
const MS_INTERVAL = 10000;
const requestOptions = {
method: "GET",
uri: `https://api.coingecko.com/api/v3/coins/${COIN_ID}`,
json: true,
gzip: true,
};
client.on("ready", () => {
setInterval(() => {
rp(requestOptions)
.then(({ market_data }) => {
const price = market_data.current_price.brl.toLocaleString("pt-BR", {
style: "currency",
currency: COIN_CURRENCY,
});
const percent_24h = market_data.price_change_percentage_24h;
const arrow = percent_24h > 0 ? "↗" : "↘";
client.user.setActivity(
`${price} ${arrow} ${percent_24h.toFixed(2)}%`,
{
type: "PLAYING",
}
);
})
.catch((err) => {
console.log("ERROR:", err);
});
}, MS_INTERVAL);
});
client.login(DISCORD_BOT_TOKEN);