forked from Astrydax/SWEotE-Discord-Dice-Roller
-
Notifications
You must be signed in to change notification settings - Fork 42
/
index.js
66 lines (54 loc) · 1.93 KB
/
index.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
/*
Developed by Astrydax, aka Royalcrown28 for vampwood
For Custom Discord Bots please email me at [email protected]
*/
const { Client, Options } = require('discord.js');
const { Patreon, token, babyBotToken } = require('./config');
const axios = require('axios');
const handlers = require('./handlers');
const ClientOptions = {
makeCache: Options.cacheWithLimits({
MessageManager: 10
}),
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
intents: ['GUILDS', 'GUILD_MESSAGES', 'DIRECT_MESSAGES']
};
const client = new Client(ClientOptions);
client.login(token).catch(error => console.error(error));
// Register our event handlers (defined below):
client.on('messageCreate', message => handlers.onMessage({ message, client }));
client.on('ready', async () => {
//const guild = await client.guilds.fetch(Patreon.guild);
//await guild.members.fetch().catch(console.error);
});
client.on('threadCreate', async (thread) => {
if (thread.joinable) await thread.join();
}
);
const checkWithBabyBot = async (userId = '') => {
const response = await axios.get(`https://discordapp.com/api/guilds/${Patreon.guild}/members/${userId}`, {
'headers': { 'Authorization': `Bot ${babyBotToken}` },
'timeout': 1000
}).catch(()=> {});
if (response && response.data && response.data.roles) {
if (response.data.roles.some(role => role === Patreon.role)) {
if(response.data.nick) return response.data.nick;
else return response.data.user.username
}
}
};
const sendMessage = async ({ message, embed, text, attachment }) => {
const response = {};
if (text) {
response.content = text;
}
if (attachment) {
response.files = [attachment];
}
if (embed) {
response.embeds = [embed];
}
message.channel.send(response).catch(console.error);
}
exports.sendMessage = sendMessage;
exports.checkWithBabyBot = checkWithBabyBot;