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 @@

Installation

# with npm
npm install djs-marshal --save
# with yarn
yarn add djs-marshal

# this package also requires discord.js
npm install discord.js --save
- -

Quick Start

+
+

Setup

-

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.

-

Legend

  • Property
  • Method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file +

Legend

  • Property
  • Method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/docs/interfaces/MarshalOptions.html b/docs/interfaces/MarshalOptions.html index 63b7057..2469ee5 100644 --- a/docs/interfaces/MarshalOptions.html +++ b/docs/interfaces/MarshalOptions.html @@ -1,17 +1,17 @@ MarshalOptions | djs-marshal
Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface MarshalOptions

Options for initializing bot. Intents are required

-

Hierarchy

  • ClientOptions
    • MarshalOptions

Index

Properties

Optional allowedMentions

allowedMentions?: MessageMentionOptions

Optional failIfNotExists

failIfNotExists?: boolean

Optional http

http?: HTTPOptions

intents

intents: BitFieldResolvable<IntentsString, number>

Optional invalidRequestWarningInterval

invalidRequestWarningInterval?: number

Optional logLevel

logLevel?: logLevel
+

Hierarchy

  • ClientOptions
    • MarshalOptions

Index

Properties

Optional allowedMentions

allowedMentions?: MessageMentionOptions

Optional failIfNotExists

failIfNotExists?: boolean

Optional http

http?: HTTPOptions

intents

intents: BitFieldResolvable<IntentsString, number>

Optional invalidRequestWarningInterval

invalidRequestWarningInterval?: number

Optional logLevel

logLevel?: logLevel

Specifies what information should be logged to the console

-

Optional logStyle

logStyle?: logStyle
+

Optional logStyle

logStyle?: logStyle

How much information should be logged

Optional makeCache

makeCache?: CacheFactory

Optional messageCacheLifetime

messageCacheLifetime?: number
deprecated

Use makeCache with a LimitedCollection for MessageManager instead.

Optional messageSweepInterval

messageSweepInterval?: number
deprecated

Use makeCache with a LimitedCollection for MessageManager instead.

-

Optional partials

partials?: PartialTypes[]

Optional presence

presence?: PresenceData

Optional readyMessage

readyMessage?: string
+

Optional partials

partials?: PartialTypes[]

Optional presence

presence?: PresenceData

Optional readyMessage

readyMessage?: string

Message to be logged when bot is ready

-

Optional rejectOnRateLimit

rejectOnRateLimit?: string[] | ((data: RateLimitData) => boolean | Promise<boolean>)

Optional restGlobalRateLimit

restGlobalRateLimit?: number

Optional restRequestTimeout

restRequestTimeout?: number

Optional restSweepInterval

restSweepInterval?: number

Optional restTimeOffset

restTimeOffset?: number

Optional restWsBridgeTimeout

restWsBridgeTimeout?: number

Optional retryLimit

retryLimit?: number

Optional shardCount

shardCount?: number

Optional shards

shards?: number | number[] | "auto"

Optional slashCommandsPath

slashCommandsPath?: string
+

Optional rejectOnRateLimit

rejectOnRateLimit?: string[] | ((data: RateLimitData) => boolean | Promise<boolean>)

Optional restGlobalRateLimit

restGlobalRateLimit?: number

Optional restRequestTimeout

restRequestTimeout?: number

Optional restSweepInterval

restSweepInterval?: number

Optional restTimeOffset

restTimeOffset?: number

Optional restWsBridgeTimeout

restWsBridgeTimeout?: number

Optional retryLimit

retryLimit?: number

Optional shardCount

shardCount?: number

Optional shards

shards?: number | number[] | "auto"

Optional slashCommandsPath

slashCommandsPath?: string

Path to the slash commands directory

-

Optional token

token?: string
+

Optional token

token?: string

The bot token. Logs in the bot if provided

-

Optional userAgentSuffix

userAgentSuffix?: string[]

Optional ws

ws?: WebSocketOptions

Methods

Optional logMethod

  • logMethod(message: string, level: logLevel): void

Optional userAgentSuffix

userAgentSuffix?: string[]

Optional ws

ws?: WebSocketOptions

Methods

Optional logMethod

  • logMethod(message: string, level: logLevel): void

Legend

  • Property
  • Method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/docs/modules.html b/docs/modules.html index d34bb02..02a45b6 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -1,8 +1,18 @@ -djs-marshal
Options
All
  • Public
  • Public/Protected
  • All
Menu

djs-marshal

Index

Type aliases

BaseSlashCommand

BaseSlashCommand: ChatInputApplicationCommandData & { beforeExecute?: { defer?: boolean; deferEphemeral?: boolean }; execute: any }

CommandCollection

CommandCollection: Collection<Snowflake | "global", SlashCommand[]>

GuildSlashCommand

GuildSlashCommand: BaseSlashCommand & { allowWithPermission?: PermissionString[]; commandType: "guild"; guildId: Snowflake }

RegularSlashCommand

RegularSlashCommand: BaseSlashCommand & { commandType: "global" | "allGuild" }

SlashCommand

logLevel

logLevel: "verbose" | "warn" | "erroronly"

logStyle

logStyle: "none" | "simple" | "expanded"

Properties

default

default: { handleInteraction: (int: Interaction) => Promise<void>; initializeBot: (options: MarshalOptions) => Client<boolean>; loadCommands: (client: Client<boolean>, commands: SlashCommand[]) => Promise<void>; loadCommandsFromDir: (client: Client<boolean>, dir: string) => Promise<void> }

Type declaration

  • handleInteraction: (int: Interaction) => Promise<void>
      • (int: Interaction): Promise<void>
      • +djs-marshal
        Options
        All
        • Public
        • Public/Protected
        • All
        Menu

        djs-marshal

        Index

        Type aliases

        BaseSlashCommand

        BaseSlashCommand: ChatInputApplicationCommandData & { beforeExecute?: { defer?: boolean; deferEphemeral?: boolean }; execute: any }

        CommandCollection

        CommandCollection: Collection<Snowflake | "global", SlashCommand[]>

        GuildSlashCommand

        GuildSlashCommand: BaseSlashCommand & { allowWithPermission?: PermissionString[]; commandType: "guild"; guildId: Snowflake }

        RegularSlashCommand

        RegularSlashCommand: BaseSlashCommand & { commandType: "global" | "allGuild" }

        SlashCommand

        logLevel

        logLevel: "verbose" | "warn" | "erroronly"

        logStyle

        logStyle: "none" | "simple" | "expanded"

        Properties

        default

        default: { handlers: { handleGuildJoin: (guild: Guild) => void; handleGuildMemberUpdate: (oldM: GuildMember | PartialGuildMember, newM: GuildMember) => Promise<void>; handleInteraction: (int: Interaction) => Promise<void> }; initializeBot: (options: MarshalOptions) => Client<boolean>; loadCommands: (client: Client<boolean>, commands: SlashCommand[]) => Promise<void>; loadCommandsFromDir: (client: Client<boolean>, dir: string) => Promise<void> }

        Type declaration

        • handlers: { handleGuildJoin: (guild: Guild) => void; handleGuildMemberUpdate: (oldM: GuildMember | PartialGuildMember, newM: GuildMember) => Promise<void>; handleInteraction: (int: Interaction) => Promise<void> }
          • handleGuildJoin: (guild: Guild) => void
              • (guild: Guild): void
              • +

                Registers commands in a guild when joined

                +

                Parameters

                • guild: Guild
                  +

                  The Guild joined

                  +

                Returns void

          • handleGuildMemberUpdate: (oldM: GuildMember | PartialGuildMember, newM: GuildMember) => Promise<void>
              • (oldM: GuildMember | PartialGuildMember, newM: GuildMember): Promise<void>
              • +

                Refreshes command permissions when a member is updated

                +

                Parameters

                • oldM: GuildMember | PartialGuildMember
                  +

                  The old member

                  +
                • newM: GuildMember
                  +

                  The updated member

                  +

                Returns Promise<void>

          • handleInteraction: (int: Interaction) => Promise<void>
              • (int: Interaction): Promise<void>
              • Checks incoming interactions and executes slash commands if any

                Parameters

                • int: Interaction

                  The incoming interaction

                  -

                Returns Promise<void>

          • initializeBot: (options: MarshalOptions) => Client<boolean>
      • initializeBot: (options: MarshalOptions) => Client<boolean>
          • Create and set up a bot for slash commands

            remark

            Intents need to be specified for creating the client

            Parameters

            • options: MarshalOptions
              @@ -21,22 +31,32 @@

              The bot's Client

            • dir: string

              The full path of the directory containing the command files

              -

            Returns Promise<void>

Functions

Const handleInteraction

  • handleInteraction(int: Interaction): Promise<void>

Returns Promise<void>

Functions

Const handleGuildJoin

  • handleGuildJoin(guild: Guild): void

Const handleGuildMemberUpdate

  • handleGuildMemberUpdate(oldM: GuildMember | PartialGuildMember, newM: GuildMember): Promise<void>
  • +

    Refreshes command permissions when a member is updated

    +

    Parameters

    • oldM: GuildMember | PartialGuildMember
      +

      The old member

      +
    • newM: GuildMember
      +

      The updated member

      +

    Returns Promise<void>

Const handleInteraction

  • handleInteraction(int: Interaction): Promise<void>

Const initializeBot

Returns Promise<void>

Const initializeBot

  • Create and set up a bot for slash commands

    remark

    Intents need to be specified for creating the client

    Parameters

    Returns Client<boolean>

Const loadCommands

  • loadCommands(client: Client<boolean>, commands: SlashCommand[]): Promise<void>

Returns Client<boolean>

Const loadCommands

  • loadCommands(client: Client<boolean>, commands: SlashCommand[]): Promise<void>
  • Loads slash commands and stores them as client.commands, then syncs them with Discord

    Parameters

    • client: Client<boolean>

      The bot's Client

    • commands: SlashCommand[]

      An array of SlashCommands to load

      -

    Returns Promise<void>

Const loadCommandsFromDir

  • loadCommandsFromDir(client: Client<boolean>, dir: string): Promise<void>

Returns Promise<void>

Const loadCommandsFromDir

  • loadCommandsFromDir(client: Client<boolean>, dir: string): Promise<void>
  • Loads slash commands from a specified directory (does not check sub-folders)

    remark

    All commands that need to be loaded should be in the root level

    remark

    All command files should export by default a SlashCommand structure

    @@ -44,4 +64,4 @@

    The bot's Client

  • dir: string

    The full path of the directory containing the command files

    -
  • Returns Promise<void>

    Legend

    • Property
    • Method

    Settings

    Theme

    Generated using TypeDoc

    \ No newline at end of file +

    Returns Promise<void>

    Legend

    • Property
    • Method

    Settings

    Theme

    Generated using TypeDoc

    \ No newline at end of file diff --git a/package.json b/package.json index 2ae1253..599b4e7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "djs-marshal", "description": "A simple slash command manager for typescript", - "version": "1.0.0", + "version": "1.0.1", "main": "dist/index.js", "types": "dist/index.d.ts", "repository": "https://github.com/DeathVenom54/djs-marshal.git", diff --git a/src/core/initializeBot.ts b/src/core/initializeBot.ts index d5e2367..d116a95 100644 --- a/src/core/initializeBot.ts +++ b/src/core/initializeBot.ts @@ -20,26 +20,25 @@ export const initializeBot = (options: MarshalOptions): Client => { client.logStyle = options.logStyle || 'simple'; client.logMethod = options.logMethod; + // load commands + if (options.slashCommandsPath) + loadCommandsFromDir(client, options.slashCommandsPath).catch((err) => { + throw err; + }); + // handle all sorts of interactions client.on('interactionCreate', handleInteraction); client.on('guildCreate', handleGuildJoin); client.on('guildMemberUpdate', handleGuildMemberUpdate); - client.once('ready', () => { - if (options.readyMessage) { - const logMessage = options.readyMessage - .replace('{username}', client.user?.username || 'Username not found') - .replace('{tag}', client.user?.tag || 'User tag not found'); - - console.log(logMessage); - } + if (options.readyMessage) { + const message = options.readyMessage + .replace('{username}', client.user?.username || 'Username not found') + .replace('{tag}', client.user?.tag || 'User tag not found'); - if (options.slashCommandsPath) - loadCommandsFromDir(client, options.slashCommandsPath).catch((err) => { - throw err; - }); - }); + client.once('ready', () => console.log(message)); + } if (options.token) void client.login(options.token); return client; diff --git a/src/index.ts b/src/index.ts index aa25932..3310a43 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,11 +12,22 @@ import { loadCommandsFromDir } from './core/commands/loadCommandsFromDir'; import { loadCommands } from './core/commands/loadCommands'; import { handleInteraction } from './core/handlers/handleInteraction'; +import { handleGuildJoin } from './core/handlers/handleGuildJoin'; +import { handleGuildMemberUpdate } from './core/handlers/handleGuildMemberUpdate'; + export * from './core/handlers/handleInteraction'; +export * from './core/handlers/handleGuildJoin'; +export * from './core/handlers/handleGuildMemberUpdate'; + +const handlers = { + handleInteraction, + handleGuildJoin, + handleGuildMemberUpdate, +}; export default { initializeBot, loadCommands, loadCommandsFromDir, - handleInteraction, + handlers, };