diff --git a/README.md b/README.md index 8927989..9ff85c9 100644 --- a/README.md +++ b/README.md @@ -21,30 +21,66 @@ yarn add djs-marshal npm install discord.js --save ``` -## Quick Start +## Setup -In your root file, preferably index.js/ts, initialize the bot like so +You can set up your bot to handle commands in 2 ways: -```js -import Marshal from 'djs-marshal' -import { Intents } from "discord.js"; +### initializeBot() + +This is the recommended way to set up your bot. It sets up various things +like commands' directory, logging and handlers for various events required. + +```ts +import Marshal from 'djs-marshal'; import path from 'path'; -// https://deathvenom54.github.io/djs-marshal/modules.html#initializeBot const client = Marshal.initializeBot({ - intents: [Intents.FLAGS.GUILDS], - // you can pass in the token to make the client login - // automatically - token: 'your-token-here', - // this is the folder path that contains your commands + // the path where slash commands are stored slashCommandsPath: path.join(__dirname, 'commands'), - // send all log messages + // (optional) message to log on ready event + readyMessage: 'Logged in as {tag}', + // (optional) bot's token, will login if provided + token: process.env.BOT_TOKEN, + // (default: 'warn') the level of logs to log in the console logLevel: 'verbose', - // logs messages in a detailed manner - logStyle: 'expanded' + // (default: 'simple') how to style the logs + logStyle: 'extended', }); + +// if you didn't provide the token above, log in yourself +// client.login(process.env.BOT_TOKEN); ``` + +### Doing it yourself + +I don't recommend this, but if you want to, by all means you can set it up yourself. + +```ts +import Marshal from './src/index'; +import Discord from 'discord.js'; +import path from 'path'; + +const client = new Discord.Client(); + +// load commands +Marshal.loadCommandsFromDir(path.join(__dirame, 'commands')); + +// some parameters +client.logLevel = 'warn'; +client.logStyle = 'simple'; + +// handlers +client.on('interactionCreate', Marshal.handlers.handleInteraction); +client.on('guildAdd', Marshal.handlers.handleGuildJoin); +// add this only if you have a command with allowWithPermission +client.on('guildMemberUpdate', Marshal.handlers.handleGuildMemberUpdate); + +client.login(process.env.BOT_TOKEN); +``` + +## Commands + Now in your commands' folder, you can start creating command files! Here are some examples: diff --git a/docs/assets/search.js b/docs/assets/search.js index 77ccf0b..8594db5 100644 --- a/docs/assets/search.js +++ b/docs/assets/search.js @@ -1 +1 @@ -window.searchData = {"kinds":{"64":"Function","256":"Interface","1024":"Property","2048":"Method","65536":"Type literal","4194304":"Type alias"},"rows":[{"id":0,"kind":1024,"name":"default","url":"modules.html#default","classes":"tsd-kind-property"},{"id":1,"kind":65536,"name":"__type","url":"modules.html#__type","classes":"tsd-kind-type-literal"},{"id":2,"kind":1024,"name":"initializeBot","url":"modules.html#__type.initializeBot","classes":"tsd-kind-property tsd-parent-kind-type-literal","parent":"__type"},{"id":3,"kind":65536,"name":"__type","url":"modules.html#__type.__type-2","classes":"tsd-kind-type-literal tsd-parent-kind-type-literal","parent":"__type"},{"id":4,"kind":1024,"name":"loadCommands","url":"modules.html#__type.loadCommands","classes":"tsd-kind-property tsd-parent-kind-type-literal","parent":"__type"},{"id":5,"kind":65536,"name":"__type","url":"modules.html#__type.__type-3","classes":"tsd-kind-type-literal tsd-parent-kind-type-literal","parent":"__type"},{"id":6,"kind":1024,"name":"loadCommandsFromDir","url":"modules.html#__type.loadCommandsFromDir","classes":"tsd-kind-property tsd-parent-kind-type-literal","parent":"__type"},{"id":7,"kind":65536,"name":"__type","url":"modules.html#__type.__type-4","classes":"tsd-kind-type-literal tsd-parent-kind-type-literal","parent":"__type"},{"id":8,"kind":1024,"name":"handleInteraction","url":"modules.html#__type.handleInteraction","classes":"tsd-kind-property tsd-parent-kind-type-literal","parent":"__type"},{"id":9,"kind":65536,"name":"__type","url":"modules.html#__type.__type-1","classes":"tsd-kind-type-literal tsd-parent-kind-type-literal","parent":"__type"},{"id":10,"kind":64,"name":"initializeBot","url":"modules.html#initializeBot","classes":"tsd-kind-function"},{"id":11,"kind":4194304,"name":"BaseSlashCommand","url":"modules.html#BaseSlashCommand","classes":"tsd-kind-type-alias"},{"id":12,"kind":4194304,"name":"RegularSlashCommand","url":"modules.html#RegularSlashCommand","classes":"tsd-kind-type-alias"},{"id":13,"kind":4194304,"name":"GuildSlashCommand","url":"modules.html#GuildSlashCommand","classes":"tsd-kind-type-alias"},{"id":14,"kind":4194304,"name":"SlashCommand","url":"modules.html#SlashCommand","classes":"tsd-kind-type-alias"},{"id":15,"kind":256,"name":"MarshalOptions","url":"interfaces/MarshalOptions.html","classes":"tsd-kind-interface"},{"id":16,"kind":1024,"name":"token","url":"interfaces/MarshalOptions.html#token","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"MarshalOptions"},{"id":17,"kind":1024,"name":"slashCommandsPath","url":"interfaces/MarshalOptions.html#slashCommandsPath","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"MarshalOptions"},{"id":18,"kind":1024,"name":"readyMessage","url":"interfaces/MarshalOptions.html#readyMessage","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"MarshalOptions"},{"id":19,"kind":1024,"name":"logLevel","url":"interfaces/MarshalOptions.html#logLevel","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"MarshalOptions"},{"id":20,"kind":1024,"name":"logStyle","url":"interfaces/MarshalOptions.html#logStyle","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"MarshalOptions"},{"id":21,"kind":2048,"name":"logMethod","url":"interfaces/MarshalOptions.html#logMethod","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"MarshalOptions"},{"id":22,"kind":4194304,"name":"logLevel","url":"modules.html#logLevel","classes":"tsd-kind-type-alias"},{"id":23,"kind":4194304,"name":"logStyle","url":"modules.html#logStyle","classes":"tsd-kind-type-alias"},{"id":24,"kind":4194304,"name":"CommandCollection","url":"modules.html#CommandCollection","classes":"tsd-kind-type-alias"},{"id":25,"kind":64,"name":"loadCommandsFromDir","url":"modules.html#loadCommandsFromDir","classes":"tsd-kind-function"},{"id":26,"kind":64,"name":"loadCommands","url":"modules.html#loadCommands","classes":"tsd-kind-function"},{"id":27,"kind":64,"name":"handleInteraction","url":"modules.html#handleInteraction","classes":"tsd-kind-function"}],"index":{"version":"2.3.9","fields":["name","parent"],"fieldVectors":[["name/0",[0,29.618]],["parent/0",[]],["name/1",[1,7.646]],["parent/1",[]],["name/2",[2,24.51]],["parent/2",[1,0.543]],["name/3",[1,7.646]],["parent/3",[1,0.543]],["name/4",[3,24.51]],["parent/4",[1,0.543]],["name/5",[1,7.646]],["parent/5",[1,0.543]],["name/6",[4,24.51]],["parent/6",[1,0.543]],["name/7",[1,7.646]],["parent/7",[1,0.543]],["name/8",[5,24.51]],["parent/8",[1,0.543]],["name/9",[1,7.646]],["parent/9",[1,0.543]],["name/10",[2,24.51]],["parent/10",[]],["name/11",[6,29.618]],["parent/11",[]],["name/12",[7,29.618]],["parent/12",[]],["name/13",[8,29.618]],["parent/13",[]],["name/14",[9,29.618]],["parent/14",[]],["name/15",[10,13.524]],["parent/15",[]],["name/16",[11,29.618]],["parent/16",[10,0.96]],["name/17",[12,29.618]],["parent/17",[10,0.96]],["name/18",[13,29.618]],["parent/18",[10,0.96]],["name/19",[14,24.51]],["parent/19",[10,0.96]],["name/20",[15,24.51]],["parent/20",[10,0.96]],["name/21",[16,29.618]],["parent/21",[10,0.96]],["name/22",[14,24.51]],["parent/22",[]],["name/23",[15,24.51]],["parent/23",[]],["name/24",[17,29.618]],["parent/24",[]],["name/25",[4,24.51]],["parent/25",[]],["name/26",[3,24.51]],["parent/26",[]],["name/27",[5,24.51]],["parent/27",[]]],"invertedIndex":[["__type",{"_index":1,"name":{"1":{},"3":{},"5":{},"7":{},"9":{}},"parent":{"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}}}],["baseslashcommand",{"_index":6,"name":{"11":{}},"parent":{}}],["commandcollection",{"_index":17,"name":{"24":{}},"parent":{}}],["default",{"_index":0,"name":{"0":{}},"parent":{}}],["guildslashcommand",{"_index":8,"name":{"13":{}},"parent":{}}],["handleinteraction",{"_index":5,"name":{"8":{},"27":{}},"parent":{}}],["initializebot",{"_index":2,"name":{"2":{},"10":{}},"parent":{}}],["loadcommands",{"_index":3,"name":{"4":{},"26":{}},"parent":{}}],["loadcommandsfromdir",{"_index":4,"name":{"6":{},"25":{}},"parent":{}}],["loglevel",{"_index":14,"name":{"19":{},"22":{}},"parent":{}}],["logmethod",{"_index":16,"name":{"21":{}},"parent":{}}],["logstyle",{"_index":15,"name":{"20":{},"23":{}},"parent":{}}],["marshaloptions",{"_index":10,"name":{"15":{}},"parent":{"16":{},"17":{},"18":{},"19":{},"20":{},"21":{}}}],["readymessage",{"_index":13,"name":{"18":{}},"parent":{}}],["regularslashcommand",{"_index":7,"name":{"12":{}},"parent":{}}],["slashcommand",{"_index":9,"name":{"14":{}},"parent":{}}],["slashcommandspath",{"_index":12,"name":{"17":{}},"parent":{}}],["token",{"_index":11,"name":{"16":{}},"parent":{}}]],"pipeline":[]}} \ No newline at end of file +window.searchData = {"kinds":{"64":"Function","256":"Interface","1024":"Property","2048":"Method","65536":"Type literal","4194304":"Type alias"},"rows":[{"id":0,"kind":1024,"name":"default","url":"modules.html#default","classes":"tsd-kind-property"},{"id":1,"kind":65536,"name":"__type","url":"modules.html#__type","classes":"tsd-kind-type-literal"},{"id":2,"kind":1024,"name":"initializeBot","url":"modules.html#__type.initializeBot","classes":"tsd-kind-property tsd-parent-kind-type-literal","parent":"__type"},{"id":3,"kind":65536,"name":"__type","url":"modules.html#__type.__type-5","classes":"tsd-kind-type-literal tsd-parent-kind-type-literal","parent":"__type"},{"id":4,"kind":1024,"name":"loadCommands","url":"modules.html#__type.loadCommands","classes":"tsd-kind-property tsd-parent-kind-type-literal","parent":"__type"},{"id":5,"kind":65536,"name":"__type","url":"modules.html#__type.__type-6","classes":"tsd-kind-type-literal tsd-parent-kind-type-literal","parent":"__type"},{"id":6,"kind":1024,"name":"loadCommandsFromDir","url":"modules.html#__type.loadCommandsFromDir","classes":"tsd-kind-property tsd-parent-kind-type-literal","parent":"__type"},{"id":7,"kind":65536,"name":"__type","url":"modules.html#__type.__type-7","classes":"tsd-kind-type-literal tsd-parent-kind-type-literal","parent":"__type"},{"id":8,"kind":1024,"name":"handlers","url":"modules.html#__type.handlers","classes":"tsd-kind-property tsd-parent-kind-type-literal","parent":"__type"},{"id":9,"kind":65536,"name":"__type","url":"modules.html#__type.__type-1","classes":"tsd-kind-type-literal tsd-parent-kind-type-literal","parent":"__type"},{"id":10,"kind":1024,"name":"handleInteraction","url":"modules.html#__type.__type-1.handleInteraction","classes":"tsd-kind-property tsd-parent-kind-type-literal","parent":"__type.__type"},{"id":11,"kind":65536,"name":"__type","url":"modules.html#__type.__type-1.__type-4","classes":"tsd-kind-type-literal tsd-parent-kind-type-literal","parent":"__type.__type"},{"id":12,"kind":1024,"name":"handleGuildJoin","url":"modules.html#__type.__type-1.handleGuildJoin","classes":"tsd-kind-property tsd-parent-kind-type-literal","parent":"__type.__type"},{"id":13,"kind":65536,"name":"__type","url":"modules.html#__type.__type-1.__type-2","classes":"tsd-kind-type-literal tsd-parent-kind-type-literal","parent":"__type.__type"},{"id":14,"kind":1024,"name":"handleGuildMemberUpdate","url":"modules.html#__type.__type-1.handleGuildMemberUpdate","classes":"tsd-kind-property tsd-parent-kind-type-literal","parent":"__type.__type"},{"id":15,"kind":65536,"name":"__type","url":"modules.html#__type.__type-1.__type-3","classes":"tsd-kind-type-literal tsd-parent-kind-type-literal","parent":"__type.__type"},{"id":16,"kind":64,"name":"initializeBot","url":"modules.html#initializeBot","classes":"tsd-kind-function"},{"id":17,"kind":4194304,"name":"BaseSlashCommand","url":"modules.html#BaseSlashCommand","classes":"tsd-kind-type-alias"},{"id":18,"kind":4194304,"name":"RegularSlashCommand","url":"modules.html#RegularSlashCommand","classes":"tsd-kind-type-alias"},{"id":19,"kind":4194304,"name":"GuildSlashCommand","url":"modules.html#GuildSlashCommand","classes":"tsd-kind-type-alias"},{"id":20,"kind":4194304,"name":"SlashCommand","url":"modules.html#SlashCommand","classes":"tsd-kind-type-alias"},{"id":21,"kind":256,"name":"MarshalOptions","url":"interfaces/MarshalOptions.html","classes":"tsd-kind-interface"},{"id":22,"kind":1024,"name":"token","url":"interfaces/MarshalOptions.html#token","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"MarshalOptions"},{"id":23,"kind":1024,"name":"slashCommandsPath","url":"interfaces/MarshalOptions.html#slashCommandsPath","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"MarshalOptions"},{"id":24,"kind":1024,"name":"readyMessage","url":"interfaces/MarshalOptions.html#readyMessage","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"MarshalOptions"},{"id":25,"kind":1024,"name":"logLevel","url":"interfaces/MarshalOptions.html#logLevel","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"MarshalOptions"},{"id":26,"kind":1024,"name":"logStyle","url":"interfaces/MarshalOptions.html#logStyle","classes":"tsd-kind-property tsd-parent-kind-interface","parent":"MarshalOptions"},{"id":27,"kind":2048,"name":"logMethod","url":"interfaces/MarshalOptions.html#logMethod","classes":"tsd-kind-method tsd-parent-kind-interface","parent":"MarshalOptions"},{"id":28,"kind":4194304,"name":"logLevel","url":"modules.html#logLevel","classes":"tsd-kind-type-alias"},{"id":29,"kind":4194304,"name":"logStyle","url":"modules.html#logStyle","classes":"tsd-kind-type-alias"},{"id":30,"kind":4194304,"name":"CommandCollection","url":"modules.html#CommandCollection","classes":"tsd-kind-type-alias"},{"id":31,"kind":64,"name":"loadCommandsFromDir","url":"modules.html#loadCommandsFromDir","classes":"tsd-kind-function"},{"id":32,"kind":64,"name":"loadCommands","url":"modules.html#loadCommands","classes":"tsd-kind-function"},{"id":33,"kind":64,"name":"handleInteraction","url":"modules.html#handleInteraction","classes":"tsd-kind-function"},{"id":34,"kind":64,"name":"handleGuildJoin","url":"modules.html#handleGuildJoin","classes":"tsd-kind-function"},{"id":35,"kind":64,"name":"handleGuildMemberUpdate","url":"modules.html#handleGuildMemberUpdate","classes":"tsd-kind-function"}],"index":{"version":"2.3.9","fields":["name","parent"],"fieldVectors":[["name/0",[0,32.055]],["parent/0",[]],["name/1",[1,8.076]],["parent/1",[]],["name/2",[2,26.946]],["parent/2",[1,0.608]],["name/3",[1,8.076]],["parent/3",[1,0.608]],["name/4",[3,26.946]],["parent/4",[1,0.608]],["name/5",[1,8.076]],["parent/5",[1,0.608]],["name/6",[4,26.946]],["parent/6",[1,0.608]],["name/7",[1,8.076]],["parent/7",[1,0.608]],["name/8",[5,32.055]],["parent/8",[1,0.608]],["name/9",[1,8.076]],["parent/9",[1,0.608]],["name/10",[6,26.946]],["parent/10",[7,1.31]],["name/11",[1,8.076]],["parent/11",[7,1.31]],["name/12",[8,26.946]],["parent/12",[7,1.31]],["name/13",[1,8.076]],["parent/13",[7,1.31]],["name/14",[9,26.946]],["parent/14",[7,1.31]],["name/15",[1,8.076]],["parent/15",[7,1.31]],["name/16",[2,26.946]],["parent/16",[]],["name/17",[10,32.055]],["parent/17",[]],["name/18",[11,32.055]],["parent/18",[]],["name/19",[12,32.055]],["parent/19",[]],["name/20",[13,32.055]],["parent/20",[]],["name/21",[14,15.96]],["parent/21",[]],["name/22",[15,32.055]],["parent/22",[14,1.202]],["name/23",[16,32.055]],["parent/23",[14,1.202]],["name/24",[17,32.055]],["parent/24",[14,1.202]],["name/25",[18,26.946]],["parent/25",[14,1.202]],["name/26",[19,26.946]],["parent/26",[14,1.202]],["name/27",[20,32.055]],["parent/27",[14,1.202]],["name/28",[18,26.946]],["parent/28",[]],["name/29",[19,26.946]],["parent/29",[]],["name/30",[21,32.055]],["parent/30",[]],["name/31",[4,26.946]],["parent/31",[]],["name/32",[3,26.946]],["parent/32",[]],["name/33",[6,26.946]],["parent/33",[]],["name/34",[8,26.946]],["parent/34",[]],["name/35",[9,26.946]],["parent/35",[]]],"invertedIndex":[["__type",{"_index":1,"name":{"1":{},"3":{},"5":{},"7":{},"9":{},"11":{},"13":{},"15":{}},"parent":{"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{}}}],["__type.__type",{"_index":7,"name":{},"parent":{"10":{},"11":{},"12":{},"13":{},"14":{},"15":{}}}],["baseslashcommand",{"_index":10,"name":{"17":{}},"parent":{}}],["commandcollection",{"_index":21,"name":{"30":{}},"parent":{}}],["default",{"_index":0,"name":{"0":{}},"parent":{}}],["guildslashcommand",{"_index":12,"name":{"19":{}},"parent":{}}],["handleguildjoin",{"_index":8,"name":{"12":{},"34":{}},"parent":{}}],["handleguildmemberupdate",{"_index":9,"name":{"14":{},"35":{}},"parent":{}}],["handleinteraction",{"_index":6,"name":{"10":{},"33":{}},"parent":{}}],["handlers",{"_index":5,"name":{"8":{}},"parent":{}}],["initializebot",{"_index":2,"name":{"2":{},"16":{}},"parent":{}}],["loadcommands",{"_index":3,"name":{"4":{},"32":{}},"parent":{}}],["loadcommandsfromdir",{"_index":4,"name":{"6":{},"31":{}},"parent":{}}],["loglevel",{"_index":18,"name":{"25":{},"28":{}},"parent":{}}],["logmethod",{"_index":20,"name":{"27":{}},"parent":{}}],["logstyle",{"_index":19,"name":{"26":{},"29":{}},"parent":{}}],["marshaloptions",{"_index":14,"name":{"21":{}},"parent":{"22":{},"23":{},"24":{},"25":{},"26":{},"27":{}}}],["readymessage",{"_index":17,"name":{"24":{}},"parent":{}}],["regularslashcommand",{"_index":11,"name":{"18":{}},"parent":{}}],["slashcommand",{"_index":13,"name":{"20":{}},"parent":{}}],["slashcommandspath",{"_index":16,"name":{"23":{}},"parent":{}}],["token",{"_index":15,"name":{"22":{}},"parent":{}}]],"pipeline":[]}} \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 2079ee3..5800625 100644 --- a/docs/index.html +++ b/docs/index.html @@ -16,12 +16,29 @@
# with npm
npm install djs-marshal --save
# with yarn
yarn add djs-marshal
# this package also requires discord.js
npm install discord.js --save
-
- In your root file, preferably index.js/ts, initialize the bot like so
-import Marshal from 'djs-marshal'
import { Intents } from "discord.js";
import path from 'path';
// https://deathvenom54.github.io/djs-marshal/modules.html#initializeBot
const client = Marshal.initializeBot({
intents: [Intents.FLAGS.GUILDS],
// you can pass in the token to make the client login
// automatically
token: 'your-token-here',
// this is the folder path that contains your commands
slashCommandsPath: path.join(__dirname, 'commands'),
// send all log messages
logLevel: 'verbose',
// logs messages in a detailed manner
logStyle: 'expanded'
});
+You can set up your bot to handle commands in 2 ways:
+
+
+ initializeBot()
+
+This is the recommended way to set up your bot. It sets up various things
+like commands' directory, logging and handlers for various events required.
+import Marshal from 'djs-marshal';
import path from 'path';
const client = Marshal.initializeBot({
// the path where slash commands are stored
slashCommandsPath: path.join(__dirname, 'commands'),
// (optional) message to log on ready event
readyMessage: 'Logged in as {tag}',
// (optional) bot's token, will login if provided
token: process.env.BOT_TOKEN,
// (default: 'warn') the level of logs to log in the console
logLevel: 'verbose',
// (default: 'simple') how to style the logs
logStyle: 'extended',
});
// if you didn't provide the token above, log in yourself
// client.login(process.env.BOT_TOKEN);
+
+
+ Doing it yourself
+
+I don't recommend this, but if you want to, by all means you can set it up yourself.
+import Marshal from './src/index';
import Discord from 'discord.js';
import path from 'path';
const client = new Discord.Client();
// load commands
Marshal.loadCommandsFromDir(path.join(__dirame, 'commands'));
// some parameters
client.logLevel = 'warn';
client.logStyle = 'simple';
// handlers
client.on('interactionCreate', Marshal.handlers.handleInteraction);
client.on('guildAdd', Marshal.handlers.handleGuildJoin);
// add this only if you have a command with allowWithPermission
client.on('guildMemberUpdate', Marshal.handlers.handleGuildMemberUpdate);
client.login(process.env.BOT_TOKEN);
+
+
+
+ Commands
+
Now in your commands' folder, you can start creating command files!
Here are some examples:
// ping.js|ts
import { SlashCommand } from "djs-marshal";
// a pretty basic command. command is a discord.js
// CommandInteraction and you can use its methods like
// reply, defer, editReply, etc.
const ping: SlashCommand = {
name: 'ping',
description: 'Play ping-pong with me',
commandType: 'global',
execute (command) {
command.reply('Pong!')
}
};
export default ping;
// https://deathvenom54.github.io/djs-marshal/modules.html#SlashCommand
@@ -37,4 +54,4 @@ Quick Start
Contributing
Please read CONTRIBUTING.md for the guidelines to contribute to this project.
-Generated using TypeDoc