This repository was archived by the owner on Mar 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.js
94 lines (88 loc) · 2.81 KB
/
Client.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'use strict';
let Message = require('./Message');
let PlayerManager = require('./PlayerManager');
let Utils = require('./Utils');
class Client {
/**
* @constructor
* @param {Client} client The bot client
*/
constructor(client) {
if (!client) {
throw new Error('[DISCORD.CLIENT] No client found !');
}
// The bot client
this.client = client;
// Imports the message functions
this.message = new Message(client);
// Imports the playermanager functions
this.playermanager = new PlayerManager(client);
// Imports the utils functions
this.utils = new Utils(client);
}
/**
* Changes the game of the bot
* @param {string} name The name of the game
* @returns {Promise<ClientUser>}
*/
setGame(name) {
return new Promise((resolve, reject) => {
if (name && typeof name === 'string') {
this.client.user.setPresence({
game: {
name
}
})
.then(() => {
resolve(this.client.user);
})
.catch(reject);
}
});
}
/**
* Changes the status of the bot
* @param {string} type The status
* @returns {Promise<ClientUser>}
*/
setStatus(type) {
return new Promise((resolve, reject) => {
let typeArray = ['online', 'idle', 'dnd', 'offline'];
if (type && typeof type === 'string') {
if (typeArray.includes(type)) {
this.client.user.setPresence({
status: type
})
.then(() => {
resolve(this.client.user);
})
.catch(reject);
} else {
return reject(new Error('[DISCORD.CLIENT] You must include a valid type. (online | idle | dnd | offline)'));
}
}
});
}
/**
* Leave a guild
* @param {string} id The guild ID
* @returns {Promise<string>}
*/
leaveGuild(id) {
return new Promise((resolve, reject) => {
if (id && typeof id === 'string') {
if (this.client.guilds.get(id)) {
try {
this.client.guilds.get(id).leave();
} catch (err) {
return reject(new Error(`[DISCORD.JS-EXT] An error has occured:\n\n${err.message}`));
}
resolve('Leaved!');
} else {
return reject(new Error('[DISCORD.CLIENT] You cannot leave this guild because the bot isn\'t there.'));
}
}
});
}
};
module.exports = Client;