Skip to content

chalda/DiscordBot

Repository files navigation

DiscordBot

DiscordBot is a free, open-source, extensible bot for Discord servers, built on top of discord.js. This bot is generally self-hosted either on a dedicated server (like a Raspberry pi) or general cloud hosting like AWS etc. You can think of this bot as privacy focused as you are in total control of the code, so you can be sure that your information is secure.

Features:

This bot has been in development since 2015 and has accumulated a ton of commands. Here are a few highlights:

General Commands

  • !help [command] -> Lists all commands or just help for one command.
  • !gif query -> Returns a gif connected to search query. Example = !gif dogs
  • !image query -> Returns an image from Google Images (careful, no adult filter) Example: !image dogs
  • !youtube query -> Returns a youtube link. Example: !youtube Fortnite
  • !wiki query -> Returns the summary of the first search result on Wikipedia.
  • !wolfram query -> Queries Wolfram Alpha for results.
  • !meme memetype "text1" "text2" => Returns a meme image. notice the quotes around text, they are vitally important!
  • !say text -> Make the bot say text, useful mostly in combination with alias.
  • !alias -> Create custom shorthand commands in Discord!
  • !invite -> Generates an invite link for the Bot to join the requested server, easy way to get the bot in multiple servers.
  • !twitch -> pulls info on a twitch streamer
  • !stock -> check a ticker value
  • Channel management!

do !help to get all the availble commands. Submissions for new generic commands are welcome. A lot of code is submitted and merged from users if it seems interesting enough but is not actively maintained by the main contributors so please report if you see any suspected bugs ;)

!alias can be very powerful to create shotcuts for other commands or create copypastas. eg !alias tsla stock $TSLA will create a !tsla alias to run "stock $TSLA"

Music Playback Commands

  • !play "text" -> Plays the requested song in voice channel you are in.
  • !play https://www.youtube.com/watch?v=wJelEXaPhJ8 -> Play a youtube song directly. Also supports soundcloud, spotify and a few other platforms.
  • !playlist -> add an entire playlist Supported` Platforms: Youtube, Spotify
  • !pause !resume -> self explanitory
  • !skip -> Skip currently playing song
  • !queue -> The queue of songs
  • !queue -s -> Compact version of queue
  • !shuffle -> shuffles queue
  • !stop_playback -> Clears playlist completelly
  • !dequeue [number] -> The removes song from queue

And much more! Try !help to get a full list of available commands.

Installation

This bot runs on node.js. You will need at least node 12. In order for music playback to work, you will need python and ffmpeg to be present on your system.

Linux

General

Install node 12 or newer, Python, and FFmpeg, along with a C compiler for npm to use.

Run npm install in the bot directory and make sure it passes.

Now set up your auth.json and run npm start or node discord_bot.js to test the bot out!

Ubuntu

First install the needed system dependencies: sudo apt install build-essential nodejs python ffmpeg

Now run node --version and make sure it is v12 or later. If not refer to the node.js download page to get an updated version.

Run npm install in the bot directory and make sure it passes.

Now set up your auth.json and run npm start or node discord_bot.js to test the bot out!

Windows

  1. Install node.js
  2. Install python
  3. Install Visual Studio Community
  4. Install FFmpeg
  5. Open x64 Native Tools Command Prompt for VS 2019 and cd to the bot's folder
  6. Run npm install and make sure it succeeds
  7. Set up your auth.json
  8. Run npm start or node discord_bot.js to test the bot out!

Additional Resources

Tuck 64 was kind enough to make a video walkthrough of the setup process

Setting up

Before the first run you will need to create an auth.json file. A bot token is required. The other credentials are not required for the bot to run, but they are highly recommended as commands that depend on them will not function. See auth.json.example.

Please see this excellent guide for how to create your discord bot's account and get your bot token.

Verify that the bot runs with your config by running npm start.

Running longterm

Once you've setup your keys and checked that the features you want are working, you have a couple of options for running the bot.

Selfhosted

You could run the bot along side everything else on your pc. However it's probably a good idea to run your bot on a separate computer such as a linux server or a Raspberry Pi so it does not interfere with your normal operations and to keep it running even if you were to sleep or shutdown your PC. We would recommend running the bot in "forever" mode. Run npm run forever to start the bot in a process that will restart it on crashes. If you need to stop running it, navigate to the bot installation folder in a terminal and run npx forever stopall. Running the bot in this mode will save error and console logs to err.log and out.log respectively. You can use Notepad or similar to open these files.

Cloud Hosted

There is a number of cloud hosting providers that can run small node.js applications like this. The following have been tested to work, you'll have to extrapolate if you want to use some other provider (AWS, etc)

Running on Heroku

  • Create heroku account, install heroku-cli, create a new Dyno.
  • Git clone the repo and follow the instructions in the Deploy section to setup pushing to heroku
  • Go to settings and setup Config Vars the name of the vars are exactly the same as the auth.json file. You DO NOT need the quotes around the values in config vars
  • Run heroku scale worker=1 in the bot installation directory to run the bot as a worker rather than a webserver.
  • SOME COMMANDS ARE NOT WORKING, I AM WORKING TO FIX THIS.

Running on Repl.it

You will still need to create an auth.json file with your credentials with this process, follow the steps above. Run on Repl.it

FAQ

Music is always saying "invalid video"

You likely need to update youtube-dl. you can do so with node ./node_modules/youtube-dl/scripts/download.js

I don't want some of these commands!

Most of our commands live in the plugins folder, deleting that plugin will easily remove the command. Also see permissions below.

How do I restrict a command to only certain users?

You will need to set up permissions.json. Please see permissions.json.example.

Updates

If you update the bot, please run npm update before starting it again. If you have issues with this, you can try deleting your node_modules folder and then running npm install again. Please see Installation.

RSS

You can create an rss.json file adding rss feeds as commands. See rss.json.example for details.

Special instructions for setting up google search and youtube APIs:

(thanks @SchwererKonigstiger)

  1. Create a Custom Search at: https://cse.google.com/cse/create/new

  2. Leave the first line blank, and name the search engine anything you wish.

  3. Click "Advanced Options" and then type ImageObject.

  4. Hit create.

  5. On this new page, enable the Image Search in the menu.

  6. Then press "Search engine ID" under the Details header.

  7. Copy this into the auth.json's "google_custom_search" section.

Make sure you also have your Google server API key, which is located in the "youtube_api_key" section, or the search will fail.

Help

Please check the GitHub issues page on this project. We get a lot of similar questions, and it is likely that yours has already been answered.

If you still need help, feel free to join us on Discord.

About

A chat bot for discord app based off discord.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published