npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@edixon/concord

v2.0.0

Published

Framework of Node.js to create Discord bots

Downloads

40

Readme

Concord

code style: prettier

Framework of Node.js to create Discord bots. With Concord you can create Discord bots quickly and easily. 🚀

Created with Node.js and TypeScript, all types are exposed for use.   + 💗

Installation

npm install @edixon/concord

Create an Bot

Create an instance of a bot.

// src/index.js
const { Bot } = require('@edixon/concord')

const bot = new Bot({
  token: 'DISCORD_TOKEN',
  prefix: '$'
  // ...
})

bot.start()

You can also create the bot by passing the necessary values through environments variables.

In project root create an file .env

TOKEN=xxxxxxxxxxxxxxxxxxxxxxxx.xxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxx
PREFIX=$

Then with only 2 lines of code you can have the bot runrring.

// src/index.js
const { Bot } = require('@edixon/concord')
new Bot().start()

Command File

Create file in location: ./src/commands with the following format: [commandName].command.js. Concord will automatically convert each file into executable commands. The same logic must be followed to create events.

command-file

You can also indicate the spefecific path where you want to save your commands, for example with typescript you should point to the path "outDir" indicated in the tsconfig.json file.

// src/index.ts
import { Bot } from '@edixon/concord'

const bot = new Bot({
  commandsPath: './dist/commands',
  eventsPath: './dist/events'
})

Note: by default the paths will be in './dist/commands' and ./dist/events respectively.

Note: in future versions these routes will be calculated dynamically through the tsconfig.json file

Create Commands

Commnad files can be interpreted as commands as long as they export a function with the command name.

  • javascript
module.exports.commandName = async ({ content, response }) => {
  // code
}
  • typescript
import { TCommand } from '@edixon/concord'

export const commandName: TCommand = async ({ content, response }) => {
  // code
}

Concord contains a default command called "ping" to test the connection with the bot.

command-ping

Create Events

To create events the steps are the same as for the commands, for example the "ready" event of discord.js is executed when the bot starts, for this the following file is created

import { TEvent } from '@edixon/concord'

export const ready: TEvent = async ({ channels }) => {
  const channel = channels.get('957760027102112828') // server log channel id
  channel?.general('Bot started')
}

Parameters

Each command file in Concord comes with a series of parameters injected from the framework to facilitate the handling of input data, server information and the bot's response.

Note: In future versions the number of parameters will be increased by adding variables with server information and methods that perform repetitive tasks

module.exports.commandName = async (...params) => { }

1. Client

Instance with all the properties described in the "Client" class of discord.js.

2. Content

  • params [Array]: Contains a list od messages sent after the command name. Only one should be used to separate messages.

  • message [Function]: Return an object containing the message instance with all the properties described in the "Message" class of discord.js.

// src/commands/content.command.js
module.exports.content = async ({ content, response }) => {
  const { params, message } = content

  const messageContent = message().content
  const bot = message().channel.client!.user!.username

  response.embeded({
    header: 'CONTENT',
    body: [
      {
        title: 'content',
        content: messageContent
      },
      {
        title: 'params',
        content: JSON.stringify(params)
      },
      {
        title: 'bot',
        content: bot
      }
    ]
  })
}

3. Channels

All server channels will be contained in the Channels parameter.

// src/commands/channels.command.js
module.exports.channels = async ({ channels }) => {
  const channel = channels.get('923073690920744990') // some id of a server channel

  if (channel) {
    await channel.general('Channels')
  }
}

4. Response

  • general [Function]: Send a general message

  • direct [Function]: Send a direct message to the user whon

  • embeded [Function]: Send an embeded message

// src/commands/responde.command.js
module.exports.response = async ({ response }) => {
  response.general('Message general')

  response.direct('Message direct')

  response.embeded({
    header: 'Message Embeded',
    title: 'Title',
    body: [
      {
        title: 'Title body 1',
        content: 'Content body 1'
      },
      {
        title: 'Title body 2',
        content: 'Content body 2'
      }
    ]
  })
}

License

MIT © Edixon Piña