-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
44 lines (43 loc) · 1.39 KB
/
Copy pathclient.js
File metadata and controls
44 lines (43 loc) · 1.39 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
const eventmodule = require('events')
const Websocket = require('./websocket')
const Guilds = require('./structure/Guilds');
const User = require('./structure/User')
const reqmanager = require('./reqmanager')
module.exports = class Client extends eventmodule {
/**
* Basic class for Discord client API
* @param {IDK!} option
*/
constructor(option) {
super();
if(option) {
this.option = option
};
this.up = false;
};
/**
* Login to Discord Server with the token
* Why is there an await/async keyword ?
* @param {string} token
*/
async login(token) {
this.token = token;
this.WS = new Websocket(token, this);
this.guilds = await new Guilds(token);
this.on("ready", () => {
this.up = true;
this.readyAt = new Date(Date.now());
this.readyTimestamp = Date.now();
});
this.uptime = this._getuptime();
// reqmanager('https://discord.com/api/v9/users/@me/guilds',token,{},{method:"get"})
// this.guilds.cache
reqmanager('https://discord.com/api/v9/users/@me', token, {}, {method:"get"}).then(data => {
this.user = new User(data, token);
});
};
_getuptime() {
if(!this.up) return;
return (new Date(Date.now()).getMilliseconds()) - this.readyAt.getMilliseconds();
};
};