Creating a Feature

Features are quite simple, they are loaded and run one time before your bot starts, but after all your commands and events load in. As of now there is no way to re-run features after startup, but there may be sometime in the future. Creating a Feature is extremely simple, just like everything else so far. All you need to do is create a new file in your features directory, in this case it will be "features". This file can have whatever name you like, and all you need to do is import the "Feature" class from the module, and export a new instance of the class.

JavaScript
TypeScript
JavaScript
// ./features/file_name.js
const { Feature } = require("cdcommands");
module.exports = new Feature();
TypeScript
// ./features/file_name.ts
import { Feature } from "cdcommands";
export default new Feature()

Just like with your commands and your events, a feature set up in this way will do nothing for you. All we need to do to set it up is add a single callback function as a parameter in the class. This callback function will have a single parameter in it, which will be the client as CDClient.

JavaScript
TypeScript
JavaScript
// ./features/file_name.js
const { Feature } = require("cdcommands");
module.exports = new Feature((client) => {
console.log(
`This is ${client.user.username} from "./features/file_name.js"!`,
);
});
TypeScript
// ./features/file_name.ts
import { Feature } from "cdcommands";
import { CDClient } from "cdcommands/src/types/helper.types";
export default new Feature((client: CDClient) => {
console.log(
`This is ${client.user.username} from "./features/file_name.ts"!`,
);
})

The above feature is extremely basic, and doesn't really do much for you in terms of functionality, but it should log something along the lines ofThis is Application Name from "./features/file_name.js"! in your console. You can do whatever you want in this file, and it will be run along with your bot starting up. You can add your own listeners here, although we would recommend using an Event instead, or you could start an Interval for updating mutes in your servers.

Note: Features will not be run if they are not created with the "Feature" class.