This repository has been archived by the owner on Mar 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Discord.js
53 lines (51 loc) · 1.63 KB
/
Discord.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
const Discord = require("discord.js");
const client = new Discord.Client();
const minotar = (user) => `https://minotar.net/avatar/${user}`;
let channel;
let guild;
let messageColor;
exports.setGuild = (newGuild) => (guild = newGuild);
exports.setChannel = (newChannel) => (channel = newChannel);
exports.setMessageColor = (newColor) => (messageColor = newColor);
exports.login = (token) => client.login(token);
exports.client = client;
exports.broadcast = ({ message }, player) => {
const g = client.guilds.cache.get(guild);
const c = g.channels.cache.get(channel);
const embed = new Discord.MessageEmbed()
.setAuthor(player.username, minotar(player.username))
.setColor(messageColor)
.setDescription(message);
c.send(embed);
};
exports.setChatHandler = (cb) => {
client.on("message", (message) => {
if (message.channel.id === channel && !message.author.bot) {
cb(message);
}
});
};
exports.playerJoined = (player, { online, max }) => {
const g = client.guilds.cache.get(guild);
const c = g.channels.cache.get(channel);
const embed = new Discord.MessageEmbed()
.setAuthor(
`${player.username} has joined the server!`,
minotar(player.username)
)
.setColor("GREEN");
c.send(embed);
c.setTopic(`Online: ${online}/${max}`);
};
exports.playerLeft = (player, { online, max }) => {
const g = client.guilds.cache.get(guild);
const c = g.channels.cache.get(channel);
const embed = new Discord.MessageEmbed()
.setAuthor(
`${player.username} has left the server.`,
minotar(player.username)
)
.setColor("RED");
c.send(embed);
c.setTopic(`Online: ${online}/${max}`);
};