WOKCommands
Search…
MongoDB
WOKCommands has built in MongoDB connection support. You can customize the connection options still, but this allows you to not worry about connecting to your database. Example:
JavaScript
TypeScript
index.js
const DiscordJS = require('discord.js')
const WOKCommands = require('wokcommands')
const path = require('path')
const { Intents } = DiscordJS
const client = new DiscordJS.Client({
// These intents are recommended for the built in help menu
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
],
})
client.on('ready', () => {
const dbOptions = {
// These are the default values
keepAlive: true
}
new WOKCommands(client, {
// The name of the local folder for your command files
commandsDir: path.join(__dirname, 'commands'),
// Pass in the new dbOptions
dbOptions,
// Pass in your own mongo connection URI
mongoUri: ''
})
})
client.login('YOUR TOKEN HERE')
index.ts
import DiscordJS, { Intents } from 'discord.js'
import WOKCommands from 'wokcommands'
import path from 'path'
const client = new DiscordJS.Client({
// These intents are recommended for the built in help menu
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
],
})
client.on('ready', () => {
const dbOptions = {
// These are the default values
keepAlive: true
}
new WOKCommands(client, {
// The name of the local folder for your command files
commandsDir: path.join(__dirname, 'commands'),
// Allow importing of .ts files if you are using ts-node
typeScript: true,
// Pass in the new dbOptions
dbOptions,
// Pass in your own mongo connection URI
mongoUri: ''
})
})
client.login('YOUR TOKEN HERE')
.env
MONGO_URI=YOUR_URI_HERE

Listening for when the database is connected

A custom event is fired whenever the database is connected, read more about it here.

Accessing built-in Mongo models/schemas

You can access any of the built-in models by accessing the MongoDB connection and then accessing the model from the models array like so:
JavaScript
TypeScript
index.js
const DiscordJS = require('discord.js')
const WOKCommands = require('wokcommands')
const path = require('path')
const { Intents } = DiscordJS
const client = new DiscordJS.Client({
// These intents are recommended for the built in help menu
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
],
})
client.on('ready', () => {
const dbOptions = {
// These are the default values
keepAlive: true,
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
}
const wok = new WOKCommands(client, {
// The name of the local folder for your command files
commandsDir: path.join(__dirname, 'commands'),
// Pass in the new dbOptions
dbOptions,
// Pass in your own mongo connection URI
mongoUri: ''
})
wok.on('databaseConnected', async (connection, state) => {
const model = connection.models['wokcommands-languages']
const results = await model.countDocuments()
console.log(results)
})
})
client.login('YOUR TOKEN HERE')
index.ts
import DiscordJS, { Intents } from 'discord.js'
import WOKCommands from 'wokcommands'
import path from 'path'
const client = new DiscordJS.Client({
// These intents are recommended for the built in help menu
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
],
})
client.on('ready', () => {
const dbOptions = {
// These are the default values
keepAlive: true,
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
}
const wok = new WOKCommands(client, {
// The name of the local folder for your command files
commandsDir: path.join(__dirname, 'commands'),
// Pass in the new dbOptions
dbOptions,
// Pass in your own mongo connection URI
mongoUri: ''
})
wok.on('databaseConnected', async (connection, state) => {
const model = connection.models['wokcommands-languages']
const results = await model.countDocuments()
console.log(results)
})
})
client.login('YOUR TOKEN HERE')
Here is a list of all mongo models/schemas:
  • wokcommands-cooldowns
  • wokcommands-disabled-commands
  • wokcommands-languages
  • wokcommands-prefixes
  • wokcommands-required-roles
  • wokcommands-channel-commands
  • wokcommands-slash-commands