@edixon/concord
v2.0.0
Published
Framework of Node.js to create Discord bots
Downloads
40
Maintainers
Readme
Concord
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.
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.
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 messagedirect [Function]
: Send a direct message to the user whonembeded [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