Skip to content

Gelean/deldbot

Repository files navigation

Deldbot

Deldbot is a Discord Bot written in Node.js, utilizing Discord.js and several other open source libraries

Software, Libraries, and APIs

Installation & Configuration

These steps provide a good walkthrough of creating and running a Discord bot: https://www.digitaltrends.com/gaming/how-to-make-a-discord-bot/

  1. Go to discordapp.com/developers/applications
  2. Click on New Application and supply a name
  3. Click on your new application
  4. Copy the Client ID and Client Secret
  5. Click on Bot under Settings on the left hand side
  6. Enter a username and copy the Token
  7. Check what permissions will be needed, all of the text permissions should be sufficient (522304)
  8. Open up the following URL, replacing the CLIENT_ID and permissions with your own values: https://discordapp.com/oauth2/authorize?&client_id=CLIENT_ID&scope=bot&permissions=0
  9. On this GitHub page click on Code -> Download ZIP
  10. Unzip the repository code somewhere on your machine
  11. Open up the Windows CMD prompt and run as administrator or open up a Linux terminal
  12. Change directory to where the downloaded code resides
  13. Run the following: npm install
    1. Optional: if you run into cache issues use the following: npm cache clean --force
  14. Copy ./config.json into ./.env/config.json
  15. Go through the following and generate API keys and tokens for the functionality you want
    1. Obtain the Plex token of your server by referencing the following link: https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/
    2. Obtain an OMDb API key from https://www.omdbapi.com/apikey.aspx
    3. Obtain an ITAD API key by setting up an account and creating a new application at https://isthereanydeal.com/dev/app
    4. Obtain a Youtube API key by setting up an account and creating a new application at https://console.developers.google.com/apis/credentials and enable the YouTube Data API v3 at https://console.developers.google.com/apis/api/youtube.googleapis.com/overview
    5. Obtain a Finnhub API key from https://finnhub.io/docs/api
    6. Register an application and obtain an Imgur client id and secret from https://api.imgur.com/oauth2/addclient
    7. Obtain a CoinMarketCap API key from https://coinmarketcap.com/api
    8. Obtain a ChatGPT API key from https://platform.openai.com/account/api-keys
  16. Update ./.env/config.json with your Discord bot's client id, client secret, token, Plex id, Plex token, Plex username, Plex password, Plex token, Plex server hostname, Plex server port, OMDB API key, ITAD API key, Finnhub API key, Youtube API key, Imgur client ID, Imgur client secret, Imgur album ID, CoinMarketCap API key, ChatGPT API key, and ChatGPT organization you wish to use. Many of these are optional depending on what functionality you would like to use.
  17. In Discord, go to User Settings > Appearance, enable Developer Mode, right-click your username, Copy ID, paste that number into the owner.id key in ./.env/config.json
  18. Run the following: npm run start or node bot.js
    1. If you wish to use pm2 to run the bot to ensure it restarts automatically from crashes, run the following: pm2 start bot.js
    2. You may need to install pm2 with: sudo npm install pm2 -g
  19. Voila, you can now start to issue commands in your Discord server and test out if the bot is working right

Docker image

Setup the Docker container

  1. cd to the root of the deldbot folder
  2. docker build -t deldbot-image:latest -f docker/Dockerfile .
  3. docker run -it deldbot-image:latest sh
  4. docker ps -a

Tear down the Docker container

  1. docker rm $(docker stop $(docker ps -aq --filter ancestor=deldbot-image --format="{{.ID}}"))
  2. Alternate tear down commands:
    1. docker ps -aq | xargs -n 1 docker stop
    2. docker ps -aq | xargs -n 1 docker rm
  3. docker system prune -a
  4. docker images -a

Running Jest Tests

npm run test

Webhooks

  1. Discord Webhooks: https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks
  2. Plex Webhooks: https://tautulli.com/ and https://github.com/Tautulli/Tautulli-Wiki/wiki/Notification-Agents-Guide#discord
  3. GitHub Webhooks: https://gist.github.com/jagrosh/5b1761213e33fc5b54ec7f6379034a22
  4. Gitlab Webhooks: https://docs.gitlab.com/ee/user/project/integrations/webhooks.html
  5. Integromat: https://www.integromat.com/

Commands and Features

See: src/commands for a list of available commands or run !help for more information

Links and References