To start using the package, you need to install it. After installing it, you have to add it as a property to the Discord client (this is not necessary, but recommended if you want to use it throughout your code).
You can add it to the Discord client in the following ways:
Method 1:
I do not recommend this method as it will not show up in the intellisense of your code editor.
const Discord = require('discord.js')
const { LevelManager } = require('discord-xplus')
const client = new Discord.Client({
intents: [Discord.GatewayIntentBits.Guilds]
})
client.once('ready', bot => {
client.levelManager = new LevelManager(client, {
mongoUri: 'your mongo uri',
})
})
// Ready event
client.levelManager.once('managerReady', () => {
console.log('LevelManager is ready!')
})
client.login('your token')
Method 2:
This is the method I prefer and find more modular, and it will work in the intellisense of your code editor.
const Discord = require('discord.js')
const { LevelManager } = require('discord-xplus')
class MyClient extends Discord.Client {
constructor(options){
super(options)
this.levelManager = new LevelManager(this, {
mongoUri: 'your mongo uri',
})
}
}
const client = new MyClient({
intents: [Discord.GatewayIntentBits.Guilds]
})
client.levelManager.once('managerReady', () => {
console.log('LevelManager is ready!')
})
client.login('your token')
When using this method, it is recommended to use the managerReady
event to know when the manager is ready to be used, as the manager internally uses the ready
event to know when the Discord client is ready and thus start the manager and its functions.