A discord bot build with node.js
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
Go to file
Trivernis f101b8f75c
Update CHANGELOG.md
5 years ago
.circleci Fixed CircleCi configuration 6 years ago
commands Database and music fix 5 years ago
lib Music fix... again 5 years ago
test Added lib/state 6 years ago
web Fixes to music functions and commands 6 years ago
.gitignore Restructured Tests 6 years ago
CHANGELOG.md Update CHANGELOG.md 5 years ago
LICENSE Create LICENSE 6 years ago
README.md Generic Database Connection 6 years ago
bot.js Music fix... again 5 years ago
package.json Merge branch 'dependency-updates' into develop 5 years ago
renovate.json Update renovate.json 5 years ago

README.md

discordbot License: GPL v3 CircleCI CodeFactor

A bot that does the discord thing.

Installation

You can easily install everything with npm npm i. If you run into an error see the discord.js installation guide or open an issue. If you run into an error with ffmpeg-binaries try using nodejs v10.15.0

Running

node bot.node [--token=<DiscordBotToken>] [--ytapi=<GoogleApiKey>] [--owner=<DiscordTag>] [--prefix=<Char>] [--game=<String>] [-i=<Boolen>]

The arguments are optional because the token and youtube-api-key that the bot needs to run can also be defined in the config.json in the bot's directory:

// config.json
{
  "prefix": "_",
  "presence": "STRING",   // this will be shown when no presences are set in data/presences.txt
  "presence_duration": 300000,  // how long does the bot have one presence
  "maxCmdSequenceLength": 10, // the maximum number of commands a sequence is allowed to have
  "rateLimitCount": 5,  // the number of messages a user is allowed to send in rateLimitTime seconds
  "rateLimitTime": 10, // the time in which a user is allowed to send rateLimitCount messages (in seconds)
  "api": {
    "botToken": "YOUR DISCORD BOT TOKEN",   
    "youTubeApiKey": "YOUR YOUTUBE API KEY"
  },
  "owners": [
    "DISCORD NAME"  // specify a list of bot owners that can use the owner commands
  ],
  "music": {
    "timeout": 300000,   // exit timeout after noone is left in the voicechannel
    "livePuffer": 20000, // the preloaded video length (see ytdl-core module)
  },
  "webservice": {     // optional
    "enabled": true,  // enable the server
    "port": 8080,     // set the port
    "graphiql": false, // switch the graphiql interface on/off,
    "sessionSecret": "PROVIDE A SECURE SECRET",
    "https": {
      "enabled": true, //enable https
      "keyFile": "PATH TO YOUR SSL KEY FILE",
      "certFile": "PATH TO YOUR SSL CERTIFICATE FILE"
    }
  },
  "commandSettings": {
    "maxSequenceParallel": 5, // the maximum number of commands executed in parallel
    "maxSequenceSerial": 10 // the maximum number of commands executed in serial
  },
  "database": "postgres or sqlite", // choose one
  "databaseConnection": {
    "user": "USERNAME",
    "host": "HOSTNAME OR IP",
    "password": "DATABASE USERPASSWORD",
    "database": "BOT DATABASE NAME", // the database needs to exist
    "port": 5432 // the port of the database server
  }
}

If the keys are missing from the config file, the bot exits. This behaviour can be deactivated by setting the -i commandline flag. You need to create a user to access the webinterface. Use ~createUser [name] [password] [scope] to create one (Only works via PM). Please provide a SECURE sessionSecred. To enable https you need a certificate and key file. Those can be generated with openssl.

Keys

You can get the API-Keys here:

Discord Bot Token

YouTube API Key

Features

At the moment the bot can...

  • ...play music (YouTube videos and playlists)
  • ...save songs/playlists with a given name
  • ...log stuff in a database
  • ...execute multiple commands as a sequence
  • ...save command sequences with a given name
  • ...query AniList
  • ...transform into a cow

Presences

You can add presences to the bot either by owner command addpresence or by providing a presences.txt file in the data directory. Each line represents a presence.

When all lines are loaded by the bot, the file gets deleted.

Command Sequences

A command sequence is a single message with several commands seperated by a semicolon. In a sequence the command can be ommitted if it is the same as the previous one. That means you can add several videos to the queue and shuffle it afterwards with the sequence ~play [video1] && ~play [video2]; ~play [video3] && ~shuffle.

A command sequence can be saved with ~savecmd [commandname] [sequence]. In this case the semicolon must be escaped with a backslash so it won't get interpreted as a seperate command. You can also escape sequences with ~play "whatever &&; you want" (doublequotes). Command sequences with && are executed in serial while command sequences with ; are executed in parallel. A saved command can be executed with ~execute [commandname].

References

You can test a running version of the bot. Invite bot server

Ideas

  • command replies saved in file (server specific file and global file)
  • reddit api
  • othercoolstuff api