/
quickmongo.js
60 lines (51 loc) · 2.08 KB
/
quickmongo.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
const Discord = require('discord.js');
const client = new Discord.Client({
intents: [Discord.IntentsBitField.Flags.Guilds, Discord.IntentsBitField.Flags.GuildVoiceStates]
});
// Load quickmongo
const { Database } = require('quickmongo');
const guildDB = new Database('mongodb://localhost/database', { collectionName: 'guilds' });
// Start the manager only after the DB turned ready to prevent an error
guildDB.once('ready', () => client.voiceTimeManager._init());
const { VoiceTimeManager } = require('discord-voice');
const VoiceTimeManagerWithOwnDatabase = class extends VoiceTimeManager {
// This function is called when the manager needs to get all guilds which are stored in the database.
async getAllGuilds() {
// Get all guilds from the database
return (await guildDB.all()).map((element) => element.data);
}
// This function is called when a guild needs to be saved in the database.
async saveGuild(guildId, guildData) {
// Add the new guild data to the database
await guildDB.set(guildId, guildData);
// Don't forget to return something!
return true;
}
// This function is called when a guild needs to be edited in the database.
async editGuild(guildId, guildData) {
// Replace the unedited guild with the edited guild
await guildDB.set(guildId, guildData);
// Don't forget to return something!
return true;
}
// This function is called when a guild needs to be deleted from the database.
async deleteGuild(guildId) {
// Remove the guild from the database
await guildDB.delete(guildId);
// Don't forget to return something!
return true;
}
};
// Create a new instance of your new class
const manager = new VoiceTimeManagerWithOwnDatabase(client, {
default: {
trackBots: false,
trackAllChannels: true
}
});
// We now have a voiceTimeManager property to access the manager everywhere!
client.voiceTimeManager = manager;
client.on('ready', () => {
console.log('Bot is ready!');
});
client.login(process.env.DISCORD_BOT_TOKEN);