WOKCommands
Search…
What is a feature?
A "feature" within WOKCommands is a normal feature within your bot. This could be a "reaction roles" system, or a "welcome message" system. A feature could include multiple event listeners and other logic to handle how your bot works. WOKCommands makes it easy to register features by adding them to a features folder. The folder name can be specified when initializing WOKCommands 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', () => {
new WOKCommands(client, {
// The name of the local folder for your command files
commandsDir: path.join(__dirname, 'commands'),
// The name of the local folder for your feature files
featuresDir: path.join(__dirname, 'features')
})
})
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', () => {
new WOKCommands(client, {
// The name of the local folder for your command files
commandsDir: path.join(__dirname, 'commands'),
// The name of the local folder for your features files
featuresDir: path.join(__dirname, 'features'),
// Allow importing of .ts files if you are using ts-node
typeScript: true,
})
})
client.login('YOUR TOKEN HERE')
You can then create a "features" folder and all of your features can be placed in that folder. These files will be automatically imported and ran and it is assumed that these files will export a function like so:
JavaScript
TypeScript
welcome-message.js
module.exports = (client, instance) => {
// Listen for new members joining a guild
client.on("guildMemberAdd", (member) => {
// Access the guild that they joined
const { guild } = member
// Get the channel named "welcome"
const channel = guild.channels.cache.find(
(channel) => channel.name === "welcome"
)
// Ensure this channel exists
if (!channel) {
return
}
// Send the welcome message
channel.send(`Welcome ${member} to the server!`)
})
}
welcome-message.ts
import { Client, TextChannel } from 'discord.js'
import WOKCommands from 'wokcommands'
export default (client: Client, instance: WOKCommands) => {
// Listen for new members joining a guild
client.on('guildMemberAdd', (member) => {
// Access the guild that they joined
const { guild } = member
// Get the channel named "welcome"
const channel = guild.channels.cache.find(
(channel) => channel.name === 'welcome'
) as TextChannel
// Ensure this channel exists
if (!channel) {
return
}
// Send the welcome message
channel.send({
content: `Welcome ${member} to the server!`,
})
})
}
This feature will be automatically ran and it's exported function will be invoked. This way you can easily register listeners and handle each of your feature's.
Copy link