This repository has been archived by the owner on Oct 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
47 lines (39 loc) · 1.65 KB
/
main.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
// Invite Link -> https://discordapp.com/api/oauth2/authorize?client_id=YOUR_SERVER_ID&permissions=3072&scope=bot
const Discord = require('discord.js');
const client = new Discord.Client();
const HytaleApi = require('hytale-api-sdk');
const api = new HytaleApi.ArticlesApi();
// bot connected to discord
client.once('ready', () => {
console.log('Ready!');
});
// catch errors
client.on("error", (e) => console.log(e));
client.on('message', message => {
if (message.content === 'h!news') {
console.log('h!news');
api.getArticles({}, function(error, data, response) {
if (error) {
console.error(error);
} else {
// get 3 latest articles
const latest = data.slice(0, 3);
latest.forEach(function (article) {
const publishAt = new Date(article.publishedAt);
const embed = new Discord.RichEmbed()
.setColor(3447003)
.setThumbnail(`https://cdn.hytale.com/variants/blog_cover_${article.coverImage.s3Key}`)
.setAuthor('HytaleBot', 'https://hytale.com/favicon.ico')
.setTitle(article.title)
.setDescription(article.bodyExcerpt)
.setURL(`https://hytale.com/news/${publishAt.getFullYear()}/${publishAt.getMonth() + 1}/${article.slug}`)
.addField('Published At', `${publishAt.toLocaleDateString()}`)
;
message.channel.send({embed});
});
}
});
}
});
// start bot
client.login('YOUR_TOKEN_HERE');