This repository was archived by the owner on Nov 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
74 lines (62 loc) · 1.84 KB
/
index.js
File metadata and controls
74 lines (62 loc) · 1.84 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const { AkairoClient, CommandHandler, ListenerHandler } = require('discord-akairo');
const axios = require('axios');
require('dotenv').config();
const express = require('express');
const bodyParser = require("body-parser");
const app = express();
const port = 3000;
class MyClient extends AkairoClient {
constructor() {
super({
// Options for Akairo go here.
}, {
// Options for discord.js goes here.
});
this.commandHandler = new CommandHandler(this, {
directory: './commands/',
prefix: '.'
});
this.listenerHandler = new ListenerHandler(this, {
directory: './listeners/'
});
this.listenerHandler.setEmitters({
process: process,
});
this.commandHandler.loadAll();
this.listenerHandler.loadAll();
getToken().then(token => {
this.apiToken = token;
});
}
}
// Get client token from server
async function getToken() {
var data = {
'grant_type': 'client_credentials',
'client_id': process.env.CLIENT_ID,
'client_secret': process.env.CLIENT_SECRET
};
const token = await axios.post(`${process.env.REQUEST_URL}oauth/token`, data)
.then(function(response) {
return response.data['access_token'];
});
return token;
}
const client = new MyClient();
client.login(process.env.DISCORD_TOKEN);
client.on('ready', () => {
client.user.setStatus('idle');
client.user.setActivity('.sc', {
type: 'WATCHING'
});
console.log(`Successfully initialized.`);
});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.post('/webhook', (req, res) => {
process.emit('webhook', req.body);
return res.end();
});
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
});