@enitoni/gears-discordjs
    TypeScript icon, indicating that this package has built-in type declarations

    4.0.0 • Public • Published

    gears-discordjs

    This package adds Discord.js bindings to Gears.

    Installing

    You'll need both Discord.js and Gears for this package to work. Install like so:

    npm install @enitoni/gears @enitoni/gears-discordjs discord.js
    

    or if you use Yarn

    yarn add @enitoni/gears @enitoni/gears-discordjs discord.js
    

    Usage

    If you are using TypeScript it is important that you import the classes from this library instead of Gears itself, as this library provides Discord.js types on the generic classes.

    Here's an example

    import { matchPrefixes } from "@enitoni/gears"
    import { Bot, Adapter, CommandGroup, Command } from "@enitoni/gears-discordjs"
     
    const adapter = new Adapter({
      token: "your secret discord bot token"
    })
     
    const command = new Command()
      .match(matchPrefixes("sum "))
      .use(context => {
        const numbers = context.content.split(" ").map(n => Number(n))
        const summed = numbers.reduce((a, b) => a + b)
     
        message.channel.send(summed)
      })
     
     
    const group = new CommandGroup()
      .match(matchPrefixes("!"))
      .setCommands(sumCommand)
     
    const bot = new Bot({ adapter, commands: [group] })
     
    bot.start()
      .then(() => console.log("Connected!"))
      .catch(e => console.error(e))

    Options

    The adapter options extend ClientOptions and adds two more properties:

    • token: string - The Discord bot token used to login
    • listenToSelf: boolean (optional) - Set this to true if you want the bot to listen to its own messages, but be aware this can cause an infinite loop if you have commands that respond to things the bot says

    Matchers

    This library includes the following matchers:

    • matchAuthors - match based on message author
    • matchChannels - match based on channel name or id
    • matchChannelTypes - match based on channel type
    • matchMentions - match based on mentions
    • matchMentionsSelf - match if message contains mention of the bot
    • matchMessageTypes - match based on message types
    • matchNSFW - match if channel is NSFW
    • matchRoles - match based on role name or id

    Services

    This library includes the following services:

    • ConsoleLoggingService - logs info, warnings and errors to console

    Keywords

    none

    Install

    npm i @enitoni/gears-discordjs

    DownloadsWeekly Downloads

    13

    Version

    4.0.0

    License

    MIT

    Unpacked Size

    26.9 kB

    Total Files

    49

    Last publish

    Collaborators

    • enitoni