-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (41 loc) · 1.22 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
47
48
49
require("dotenv").config();
const Discord = require("discord.js");
const axios = require("axios");
const client = new Discord.Client();
let lastMessage = null;
const channelId = process.env.CHANNEL_ID;
function SetBotPrice() {
axios
.get("https://farmerapi.storx.io/get-asset-price")
.then((data) => {
if (data.data.status === 200) {
const SRX = data.data.data.SRXUSDT;
if (lastMessage && !isNaN(parseFloat(SRX))) {
lastMessage.guild.me.setNickname(`${SRX}`);
console.log("set nick name,", data.data.data.SRXUSDT);
} else if (lastMessage && isNaN(parseFloat(SRX))) {
lastMessage.guild.me.setNickname(`Price Bot`);
console.log("set nick name,", "Price Bot");
}
}
})
.catch((e) => {
console.error(e);
});
}
client.on("ready", () => {
console.log("I am ready!");
const channel = client.channels.cache.get(channelId);
channel.messages
.fetch({ limit: 1 })
.then((messages) => {
lastMessage = messages.first();
SetBotPrice();
})
.catch(console.error);
setInterval(SetBotPrice, 1 * 60 * 1000);
});
client.on("message", (message) => {
lastMessage = message;
});
client.login(process.env.TOKEN);