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
1
const DiscordJS = require('discord.js')
2
const WOKCommands = require('wokcommands')
3
const path = require('path')
4
5
const { Intents } = DiscordJS
6
7
const client = new DiscordJS.Client({
8
// These intents are recommended for the built in help menu
9
intents: [
10
Intents.FLAGS.GUILDS,
11
Intents.FLAGS.GUILD_MESSAGES,
12
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
13
],
14
})
15
16
client.on('ready', () => {
17
new WOKCommands(client, {
18
// The name of the local folder for your command files
19
commandsDir: path.join(__dirname, 'commands'),
20
// The name of the local folder for your feature files
21
featuresDir: path.join(__dirname, 'features')
22
})
23
})
24
25
client.login('YOUR TOKEN HERE')
Copied!
index.ts
1
import DiscordJS, { Intents } from 'discord.js'
2
import WOKCommands from 'wokcommands'
3
import path from 'path'
4
5
const client = new DiscordJS.Client({
6
// These intents are recommended for the built in help menu
7
intents: [
8
Intents.FLAGS.GUILDS,
9
Intents.FLAGS.GUILD_MESSAGES,
10
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
11
],
12
})
13
14
client.on('ready', () => {
15
new WOKCommands(client, {
16
// The name of the local folder for your command files
17
commandsDir: path.join(__dirname, 'commands'),
18
// The name of the local folder for your features files
19
featuresDir: path.join(__dirname, 'features'),
20
// Allow importing of .ts files if you are using ts-node
21
typeScript: true,
22
})
23
})
24
25
client.login('YOUR TOKEN HERE')
Copied!
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
1
module.exports = (client, instance) => {
2
// Listen for new members joining a guild
3
client.on("guildMemberAdd", (member) => {
4
// Access the guild that they joined
5
const { guild } = member
6
7
// Get the channel named "welcome"
8
const channel = guild.channels.cache.find(
9
(channel) => channel.name === "welcome"
10
)
11
12
// Ensure this channel exists
13
if (!channel) {
14
return
15
}
16
17
// Send the welcome message
18
channel.send(`Welcome ${member} to the server!`)
19
})
20
}
Copied!
welcome-message.ts
1
import { Client, TextChannel } from 'discord.js'
2
import WOKCommands from 'wokcommands'
3
4
export default (client: Client, instance: WOKCommands) => {
5
// Listen for new members joining a guild
6
client.on('guildMemberAdd', (member) => {
7
// Access the guild that they joined
8
const { guild } = member
9
10
// Get the channel named "welcome"
11
const channel = guild.channels.cache.find(
12
(channel) => channel.name === 'welcome'
13
) as TextChannel
14
15
// Ensure this channel exists
16
if (!channel) {
17
return
18
}
19
20
// Send the welcome message
21
channel.send({
22
content: `Welcome ${member} to the server!`,
23
})
24
})
25
}
Copied!
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