This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@1mmunity/discord-bot-base

2.1.8 • Public • Published

Table of contents

About

This is a discord bot base so that it is easier to start a bot. NEW: Slash Commands - Want to make a slash command easily? Well this is for you!

Installation

npm i @1mmunity/discord-bot-base

Node.js 12.0.0 or newer is required.

Getting Started

Quickstart

  1. Require it in your script.
const DBB = require('@1mmunity/discord-bot-base')
  1. Initialize the DBB Client.
const DBB = require('@1mmunity/discord-bot-base')
const client = new DBB.Client({
  ownerId: 'id'
})

See ClientOptions from the documentations

  1. Login to your client
const DBB = require('@1mmunity/discord-bot-base')
const client = new DBB.Client({
  ownerId: 'id'
})

client.login('token')
  1. Register defaults (optional)
const DBB = require('@1mmunity/discord-bot-base')
const client = new DBB.Client({
  ownerId: 'id'
})

client.registry.registerAllDefaults()

client.login('token')

That's it for a quick start! Registered events:

  • ready
  • message
  • guildCreate
  • guildDelete

Registered Commands:

  • eval - Evaluate JavaScript code
  • ban - Bans mentioned members from a guild
  • kick - Kicks mentioned members from a guild
  • warn - DMs users from a guild that they have been warned
  • help - Gets a list of commands
  • ping - Gets client's websocket ping
  • user - Gets a detailed information of a mentioned member

You set options with options.events.{event}: Boolean, options.commands.{command}: Boolean, options.prefix: String.

Examples

You can see examples in the Tests folder.
standard.js

const DBB = require('../')
const client = new DBB.Client({
  ownerId: 'id'
})

client.registry.registerAllDefaults()

client.login('token')

semi-standard.js

const DBB = require('../')
const client = new DBB.Client({
  ownerId: 'id'
})
const registry = client.registry

registry.registerDefaultCommands()
registry.registerDefaultEvents()
registry.handleEvents()
// registry.handleCommands() is used only on the message event

client.login('token')

non-standard.js

const DBB = require('../')
const client = new DBB.Client({
  ownerId: 'id'
})
const registry = client.registry

registry.addEvents([
  {
    name: 'ready',
    run: (client) => {
      console.log(`Logged in as ${client.user.tag}`)
    }
  },
  {
    name: 'message',
    run: (client, message) => {
      registry.handleCommands(message, {
        ignoreBots: true,
        guildOnly: true,
        prefix: '!',
        prefixRequired: true,
      })
    }
  }
])

// registers ready and message event

registry.addCommands([
  {
    name: 'test',
    aliases: ['t'],
    run: (client, message) => {
      return message.reply(client.user.tag)
    }
  }
])

registry.registerDefaultCommands({
  help: true
})

registry.handleEvents()

// registers test and help commands

client.login('token')

Slash Commands

Make slash commands, this is an experimental feature,

const client = new DBB.Client({
  ownerId: ''
})
const { MessageEmbed } = require('discord.js')
const slashy = client.slash({
  testServers: ['id1', 'id2']
})
// testServers is for developmental reasons, because globally it will take up to an hour.

slashy.addCommand('ping', {
  description: 'Pong',
  run: (_client, message, args) => {
    // args is for options
    // message is for interaction
    // _client is the client that interacted
    // EXAMPLE:
    return message.send('Pong!')
  }
})

// with embed, options & register more than one
slashy.addCommands([
  {
    name: 'embed',
    description: 'Sends an embed',
    run: (_client, message) => {
      return message.send(null, [
        new MessageEmbed().setTitle('Hello World'),
        new MessageEmbed().setTitle('Hello World2')
      ])
      // send(content=String, embeds=Array, hidden=Boolean)
    }
  }, {
    name: 'apply',
    description: 'Apply for Moderator',
    options: [
      {
        name: 'Age',
        description: 'Your age, must be above 18.',
        required: true,
        type: 4 // 1: COMMAND_GROUP | 2: SUB_COMMAND_GROUP | 3: String | 4: Number | 5: Boolean | 6: Mention
      },
      {
        name: 'Reason',
        description: 'Reason to become a moderator.',
        required: true,
        type: 3
      }
    ],
    run: (_client, message, args) => {
      if (args.Age < 18) return message.send('Your age must be above 18 to be a moderator!', null, true) // hidden or ephermal if last parameter is true
      if (args.Reason.toLowerCase() === 'to troll') return message.send('Sorry, we aren\'t looking for trolls.', null, true)
      // ...
      return message.send('Your application has successfully being processed, please wait until further notice.')
    }
  }
])


client.registry.addEvent('ready', () => {
  slashy.handle() // handle Interactions; slashy.postCommands() then slashy.handleCommands()
  console.log('Ready!')
})

client.registry.handleEvents()
client.login('token')
  • slashy.registerCommands(dir, options) - Registers commands, the same as registry.registerCommands(dir, options) but for slash commands, works exactly as an object of slashy.addCommands(commandsArr)

  • slashy.handleGlobal() - Works like slashy.handle(), but this is not for test servers, instead globally. Might take up to an hour, so use slashy.handle() for development.

  • run(client, message, args) => {} - message is a custom message class, it IS NOT the regular message object from discord.js.

  • message.author - Author (user) object from discord.js

  • message.member - Represents author as member from discord.js

  • message.send(msg, embeds, hidden) - You can only use this one time in your command. msg is the message you want to send (string). embeds is an array of embeds that you want to send (Can't be used in ephermal commands). args is the values of the options (object).

Documentation

Documentations for DBB. You can see the original Discord.js Documentations.

Client

new DBB.Client(ClientOptions)
Parameter Type Optional Default Description
ClientOptions object false - Options for the client, see ClientOptions
ClientOptions.ownerId string false - The bot owner's ID, used for ownerOnly property in a command

Properties

Methods

  • reportBotVitals - returns an object that has arrays of event and command names

Modules

Modules for DBB.

Registry

new Modules.Registry(client)
Parameter Type Optional Default Description
client Client false - Client that has this registry

Properties

  • client - The client that has this registry

Methods

  • registerAllDefaults(options) - Registers default commands, events, and handlers
  • registerDefaultCommands(options) - Registers default commands only
  • registerDefaultEvents(options) - Registers default events only
  • registerCommands(dir, options) - Registers all files as commands in a directory
  • registerEvents(dir) - Registers all files as events in a directory
  • handleEvents(extraArg) - Handles all events IMPORTANT
  • handleCommands(message, options) - Handles incoming messages as commands, used in the message event IMPORTANT
  • addCommand(name, props) - Adds a command with the name of name, command contents are in props
  • addEvent(name, callbackfn) - Similar to the discord.js client.on(), but this adds an event to later be triggered on handleEvents
  • addCommands(commandsArr) - Adds multiple commands as an array, similar to addCommand
  • addEvents(eventsArr) - Adds multiple events as an array, similar to addEvent
  • registerCommand(dir) - Registers a file as a command in the provided file directory
  • registerEvent(dir) - Registers a file as an event in the provided file directory

See Examples

Others

reportBotVitals

client.reportBotVitals(options, callbackfn)
Parameter Type Optional Default Description
options object true * What should be included on report
options.commands boolean true true Should commands be included
options.events boolean true true Should events be included
callbackfn Function true - Callback function when vitals are reported
callbackfn(returnObj) object true object<Array, Array> Object including events and commands array on the vitals

License

This package is licensed under MIT License.

Package Sidebar

Install

npm i @1mmunity/discord-bot-base

Weekly Downloads

1

Version

2.1.8

License

MIT

Unpacked Size

35.2 kB

Total Files

27

Last publish

Collaborators

  • 1mmunity