2.0.1 • Published 7 years ago

json-discord v2.0.1

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
7 years ago

discord.json

A library to create Discord bots in JSON

JSON Bot Format

The format of the JSON for your bot

Example

{
    "token": "BOT_TOKEN",
    "prefix": "!",
    "status": "!help",
    "commands": [
        {
            "name": "help",
            "message": "help - gets help for commands\nping - gets bot ping time\navatar - gets the url to your avatar"
        },
        {
            "name": "ping",
            "message": "Pong!",
            "edit": "Pong! <ping.difference>ms round-trip, <client.ping>ms API heartbeat"
        },
        {
            "name": "avatar",
            "message": "Your avatar URL is: <author.avatar>"
        }
    ]
}

Details

token (required): The token for your Discord bot

prefix (required): The prefix for your Discord bot (a mention prefix will also work)

status: The playing status for your Discord bot (static)

commands (required): An array of commands for your Discord bot

Command Format

name (required): The name of the command, case does not matter

message (required): The message to send as the command response (can be templated)

edit: The message to edit to after sending the first message, mainly for a ping command round-trip (can also be templated)

serverOnly: Boolean, whether or not the command is for a server only or not

Templates

There are many templates available for use in the message and message edit. Templates are in the format <category.property> (brackets included).

Note: all templates supported in message are also supported in message edit, but not the other way around

Message Templates

client.id: The id of the signed in Discord client

client.username: The username of the signed in Discord client

client.discriminator: The discriminator of the signed in Discord client

client.tag: The user tag of the signed in Discord client

client.avatar: The avatar of the signed in Discord client

client.ping: The average Discord gateway ping of the Discord client

message.id: The id of the message sent

message.content: The content of the message sent

message.createdAt: The time the message was created at

author.id: The id of the user who sent the command

author.username: The username of the user who sent the command

author.discriminator: The discriminator of the user who sent the command

author.tag: The user tag of the user who sent the command

author.avatar: The avatar of the user who sent the command

Note: with the server properties, it is recommended to only use them when you are also using the serverOnly option, otherwise the templates will not be replaced in DMs

server.id: The id of the server the command was sent in

server.name: The name of the server the command was sent in

server.members: The member count of the server the command was sent in

Message Edit Templates

ping.difference: The difference in time from the command message sent to the bot's message sent

Running Your JSON Bot

To run the bot, you have 2 options:

  • Using discord.json as a module
  • Using discord.json as a CLI

Module

npm install json-discord

Once you install json-discord into your project, you can require it and import the Bot class from it. Once you have the bot class, just make a new Bot(config) based on the JSON config for your bot.

const { Bot } = require('json-discord'); // Import the Bot class from discord.json
const config = require('./bot.json'); // You can also write an object directly into the class instead of importing a JSON file

new Bot(config);

CLI

npm install --global json-discord

Once you have discord.json installed globally, you can run (and replace bot.json for your json file's name):

djson bot.json

Success!

You have now created your own JSON based Discord bot!

2.0.1

7 years ago

2.0.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago