An open-source Discord bot built with Discord.JS & TypeScript

Overview

discord.js

Docker Pulls Docker Image Version (tag latest semver) Discord

πŸ€– Hans - Discord Bot

Discord Bot build with Discord.JS, TypeScript, and lots of ❀️

Invite hans to your server

You can invite the bot here πŸ”— . It's using the latest hans:nightly image with the latest features.

The list of commands can be found here πŸ”— and, the list of functionalities can be found here πŸ”—


Developing Hans

πŸͺ¬ NOTE: Please consider opening an issue and PR for bugs, suggestions or new features.


πŸ”… Prepare environment

Before running any command, run npm install & cp .env.template .env, fill all the env variables needed. To create your application, visit Discord's Developer Portal

πŸͺ¬ IMPORTANT: A MongoDB instance is needed for the bot to work. A free Atlas cluster should be more than enough (even for small bots & communities) for development.

An alternative is to spin a MongoDB instance yourself with Docker locally. Use docker compose up -d command to start it. docker-compose down to stop it.

MongoDB Compass is recommended. Your connection string should be mongodb://hans:S3cret@localhost:27017


πŸ‘©πŸΌβ€πŸ’» Development

npm run dev

Will start a development server with ts-node and nodemon for livereload. A bot Invite link will be displayed in the console. Use it to invite the bot to your server.

Slash commands

All commands (under src/commands) are built with the Slash Command interaction.

πŸͺ¬ IMPORTANT: before developing commands, make sure you invite the bot to your server and the entry in mongodb hans -> config has the commandsDevGuild.id set to your server id.

All commands under the main folder are available globally (it will take a second to have them available) while the ones under bots-playground are guild specific and are instantly deployed, use this folder for debugging & development purposes.

To deploy the commands: npm run slashDev or npm run slash in production.

πŸͺ¬ IMPORTANT: Since the command process is isolated, make sure to export the mongodb connection string to your current shell, ex: export MONGODB_CONNECTION="mongodb://hans:S3cret@localhost:27017"


πŸ§ͺ Testing

For testing, we use Mocha with TS.

All the tests are under the /tests directory. Right now they're none or a few, ideally, we should add more test coverage for command controllers.

npm run test

Will run all the tests.


πŸ— Production

We have multiple environments for deploying your bot (see Deployment section below). The easiest way would be to clone the repo and do:

πŸͺ¬ IMPORTANT: Make sure to follow the Prepare environment section.

npm run build

To generate the application's build.

npm start

Will run the bot with the production environment.

Other deployments

With Docker

There's an image in the DockerHub at en3sis/hans with the latest version or you can build your image. Build it locally with docker build -t en3sis/hans .

With Kubernetes

It's also possible to deploy the bot to a Kubernetes cluster, the necessary files are in the k8s folder.

Steps:

  1. You'll need your K8S cluster, ofc ;P
  2. Create the namespace kubectl apply -f k8s/namespace.yaml
  3. Run cp k8s/secrets.template.yaml k8s/secrets.yaml, fill it up and apply the secrets kubectl apply -f k8s/secrets.yaml
  4. Deploy the workload kubectl apply -f k8s/deployment.yaml
Comments
  • [BUG] ThreadChannel

    [BUG] ThreadChannel

    πŸ“ Describe the bug

    Adding a new channel object to the the threadChannels document doesn't seem to work

    🧬 To Reproduce Having multiple elements in the array's documents won't make all of them work, only the first one

    πŸ”… Expected behavior It should create a new thread in threadChannels[1].threadChannelId

    🌠 Screenshots

    image

    πŸ‘©πŸΌβ€πŸ’» Additional context

    bug 
    opened by en3sis 1
  • [BUG] messageUpdated event

    [BUG] messageUpdated event

    πŸ“ Describe the bug

    A clear and concise description of what the bug is. Not sure if there was a change in the API, but the messageUpdate:oldMessage response seems to always be undefined

    🧬 To Reproduce

    Steps to reproduce the behavior:

    1. Start your bot.
    2. Make sure your development guild has the MongoDB document for messageUpdate: true & messagesAlterations: { logChannelId: 'YOUR_CHANNEL' } set.
    3. Send a message in any chat
    4. Edit the message
    5. If you console.log the oldMessage (src/events/messageUpdate.ts) it the content is undefined

    πŸ”… Expected behavior

    A clear and concise description of what you expected to happen.

    It should show the old message content & author should be present, but they're null.

    🌠 Screenshots

    If applicable, add screenshots to help explain your problem.

    image

    πŸ‘©πŸΌβ€πŸ’» Additional context

    Add any other context about the problem here.

    Not sure if there was a change in the bot permissions level.

    bug 
    opened by en3sis 1
  • Adds the v3 of the model

    Adds the v3 of the model

    πŸ—“ Changes

    Please delete options that are not relevant.

    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [X] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • [ ] This change requires a documentation update

    Please provide enough information so that others can review your pull request:

    Adds support for GPT-3 model

    Checkboxes:

    • [X] I ran npm run lint and there were no errors
    • [X] I ran npm run format and there were no errors
    opened by en3sis 0
  • Initial configuration for openAI and GPT3

    Initial configuration for openAI and GPT3

    πŸ—“ Changes

    Please delete options that are not relevant.

    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [X] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • [ ] This change requires a documentation update

    Please provide enough information so that others can review your pull request:

    🧬 Details

    Explain the details for making this change. What existing problem does the pull request solve?

    Adds a new functionality for premium guilds that allows you to interact with Hans vΓ­a GPT-3.


    Checkboxes:

    • [X] I ran npm run lint and there were no errors
    • [X] I ran npm run format and there were no errors
    opened by en3sis 0
  • impr: reddit improvement for duplications, unit-test for some parts o…

    impr: reddit improvement for duplications, unit-test for some parts o…

    Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request.

    πŸ—“ Changes

    • [X] Bug fix (non-breaking change which fixes an issue)
    • [X] New feature (non-breaking change which adds functionality)

    🧬 Details

    Explain the details for making this change. What existing problem does the pull request solve?

    1. Adds chai library for unit-testing
    2. Improves the are same title functionality, now it covers more scenarios and tries to cache the post for 24h
    3. Adds some unit-testing for some parts of the application
    4. Fixes base64 encoding/decoding
    opened by en3sis 0
  • Ops/improvements reddit plugin

    Ops/improvements reddit plugin

    🧬 Details

    Explain the details for making this change. What existing problem does the pull request solve?

    Small plugin improvements:

    • Max description field length
    • Generic fields
    opened by en3sis 0
  • fix: Improves avoiding duplicate posts titles

    fix: Improves avoiding duplicate posts titles

    🧬 Details

    Explain the details for making this change. What existing problem does the pull request solve?

    Adds a new 'sanity check' for post titles, I know it's not perfect (since it only compares with the latest stored title) but now if a subreddit gets spammed with the same post title, the new function will try to compare them, if it matches at >= 50%, it won't repost it.

    Note: For a future improvement, we could store a temporally (x amount of days so if titles match but it's actually new content, skip the verification) all the titles that were sent and compare it with those.

    opened by en3sis 0
  • slash command to handle sentimentPlugin

    slash command to handle sentimentPlugin

    🧬 Details

    Explain the details for making this change. What existing problem does the pull request solve?

    Adds support for the moderation tool to handle the sentimentAnalysis plugin.

    opened by en3sis 0
  • [FEATURE] Disallow commands globally

    [FEATURE] Disallow commands globally

    πŸ“ Is your feature request related to a problem? Please describe.

    If we deploy a command with some bugs, we need to redeploy the bot in order to fix it.

    🧬 Describe the solution you'd like

    Add an array with disabled commands so we can do it from Hans configuration. In this case if something goes wrong, we have the force stop.

    πŸ‘©πŸΌβ€πŸ’» Additional context

    enhancement 
    opened by en3sis 0
  • Discord v14 update

    Discord v14 update

    Fix: https://github.com/en3sis/hans/issues/17

    IMPORTANT: Please do not create a Pull Request without creating an issue first.

    Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request.

    πŸ—“ Changes

    Please delete options that are not relevant.

    • [X] Bug fix (non-breaking change which fixes an issue)
    • [X] New feature (non-breaking change which adds functionality)

    🧬 Details

    Explain the details for making this change. What existing problem does the pull request solve?

    Updates to Discord.JS V14 for better support and new features.

    🧰 Fixes:

    • Fixes some issues with the Reddit Plugin
    • Cleans up unused files

    ❇️ New:

    • Reads peramaInvite link to Hans Guild from db
    enhancement 
    opened by en3sis 0
  • [FEATURE]  Reddit new messages notifications

    [FEATURE] Reddit new messages notifications

    πŸ“ Is your feature request related to a problem? Please describe. NA

    🧬 Describe the solution you'd like

    They're many cool subreddits whit excellent content, one of them being https://www.reddit.com/r/FreeGameFindings where people post free games.

    New functionality scans the subreddit every n minutes and, If a new post makes it to new sections, notify it to a given channel.

    AC:

    Plugin part As part of https://github.com/en3sis/hans/pull/15

    • [X] Should fetch the latest post
    • [X] A new database called Plugins with a collection reddit and the document with the data structure.
    • [X] Should check in the collection to see if it was already notified (in the document)
    • [X] Allow multiples guilds to subscribe to the same document
    • [X] Iterate over the list of subscribed guilds and send it to the channel

    Command part As part of https://github.com/en3sis/hans/pull/20 To enable it:

    • [X] Add a command to subscribe to a subreddit, it will create a new document in the collection (/reddit -> Subredit* -> ChannelId?* = required | ? = optional)
    • [X] It will create a new channel in the discord with some {title} where it will initialize the notifications
    • [X] It will re-post the latest post in the channel.

    Document Template

    {
      subReddit: 'javascript',
      description: 'The programming language of the web',
      latestPostId: 'foo_bar',
      subscribedGuilds: [
        {
          guildId: '123456789',
          channelId: '123456789',
        }
      ]
    }
    

    πŸ‘©πŸΌβ€πŸ’» Additional context

    enhancement plugin command 
    opened by en3sis 0
  • Init confi from Supabase

    Init confi from Supabase

    Fix: #37


    IMPORTANT: Please do not create a Pull Request without creating an issue first.

    Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request.

    πŸ—“ Changes

    Please delete options that are not relevant.

    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [ ] New feature (non-breaking change which adds functionality)
    • [X] Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • [X] This change requires a documentation update

    Please provide enough information so that others can review your pull request:

    🧬 Details

    Explain the details for making this change. What existing problem does the pull request solve?

    • Adds Supabase
    • Uses Supabase for configuration

    TODO:

    • Migrate remaining stuff (guilds, plugins..) to Supabase from Mongodb

    Checkboxes:

    • [X] I ran npm run lint and there were no errors
    • [X] I ran npm run format and there were no errors
    ops 
    opened by en3sis 0
  • [FEATURE] Plugins structure

    [FEATURE] Plugins structure

    πŸ“ Is your feature request related to a problem? Please describe.

    Right now the Plugin configuration works well but it can be improved.

    🧬 Describe the solution you'd like

    • [ ] Replicate the slashCommand folder structure and dynamic loading
    • [ ] Stores plugins in their own table in Supabase, depending on #37
    enhancement plugin 
    opened by en3sis 0
  • [FEATURE] MongoDB -> Supabase

    [FEATURE] MongoDB -> Supabase

    πŸ‘©πŸΌβ€πŸ’» Additional context

    While MongoDB works well, I want a more robust solution. I was playing around with Supabase for a few days now and seems to fit perfectly. I'll gradually move the core functionality then the Plugins section

    enhancement ops 
    opened by en3sis 0
  • [FEATURE] Self role

    [FEATURE] Self role

    πŸ“ Is your feature request related to a problem? Please describe.

    🧬 Describe the solution you'd like

    1. Have a subcommand for /moderation related to user self role where an Admin can select multiple roles from server roles.
    2. It should take @roles, channel, description where channel = channel for the message to be posted and description as message.content
    3. Create a new message, having each role as a button.
    4. When a user clicks on the given role, toggle that role for the user.

    Not sure if we need to store something per guild, but maybe.

    πŸ‘©πŸΌβ€πŸ’» Additional context

    enhancement plugin command 
    opened by en3sis 0
  • [FEATURE] using winston.js as loger

    [FEATURE] using winston.js as loger

    πŸ“ Is your feature request related to a problem? Please describe.

    A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] NA

    🧬 Describe the solution you'd like

    A clear and concise description of what you want to happen.

    Right now we have some console.log to catch HTTP requests errors and so. We want a better way to handle those errors, one idea would be using having a look at Winston (or some other alternatives)

    πŸ‘©πŸΌβ€πŸ’» Additional context

    Add any other context or screenshots about the feature request here.

    It would be also nice to have some wrapper for debugging, for example, having logs that will only show on ISDEV=true

    enhancement 
    opened by en3sis 0
  • [FEATURE ]Generic /config command for guild configuration

    [FEATURE ]Generic /config command for guild configuration

    🧬 Details

    Right now a user cannot enable plugins without editing the DB directly. This will be a multiple steps tasks.

    Step 1 : We need to create a slash command called /moderation. Requirements:

    • [X] It should only be allowed to be used by the guild owner
    • [X] It should provide multiple options, preferably plugin specific (check /src/controllers/plugins)

    Moderation plugins:

    • [X] sentimentAnalysis
    • [ ] messagesAlterations
    enhancement command 
    opened by en3sis 1
Releases(v1.1.0)
  • v1.1.0(Sep 15, 2022)

    With the release of the new version, here is the list with some of the main changes & improvements:

    ❇️ New:

    • Updates to Discord v14.3.0
    • Allows to define Hans's activity from his DB config document.
    • Adds a new (basic) Reddit plugin, allowing you to watch for specific /r and post the latest channel.
    • New /mock command, mocks a string of text based on the famous Sponge-Bob meme.
    • New /moderation->purge that removes anΒ nΒ amount of messages (max 100)
    • New /reddit command for subscribe/unsubscribe your guild to a specific /r
    • New /moderation->sentiment command for dealing with the sentiment analysis plugin (notification channel, enable/disable).
    • Improved the /support command, now has information about how to report bugs or request features.
    • User's guild settings document is now part of the Client object: Hans.guildSettings(id)
    • Bot settings document is now part of the Client object: Hans.settings.

    πŸ”… Improvements & Fixes:

    • Guilds Documents now have aΒ premium, which will allow us to define which guilds can use paid APIs like OpenAI.
    • Prepares theΒ utilsΒ forΒ crypto, in the future we want to hash things like API Keys if users need to add their own Key.
    • Changes the way we handle reading & writing plugins configuration.
    • Improved bot pulse functionality, adds more details.
    • Now the invite link can be read from Hans Settings.
    • Fixes some issues with commands permission, still room for improvements.
    • Moves guilds documents to own db (guilds) & collection (global).
    • Uses addChannelOption & addUserOption instead of string options when possible and needed.

    βš™οΈ DevOps:

    • Uses QEMU & Buildx for the multi-platform image build
    • Nightly build will happen every night at 2 AM, tagged as hans:nightly
    • Added a manual build if we need to deploy it before.
    • Adds a .prod deployment manifest for production, deployment.yaml will targetΒ nightlyΒ releases
    • Allows fetching GitHub API without a KEY for public projects
    • Adds preparation for OpenAI API
    • Adds lodash & node-cron
    • Recommended extensions for contributors.
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Sep 2, 2022)

    🐞 Fixes:

    • Fixes an issue with MongoDB connection not staying open.
    • Fixes an issue with the k8s deployment file, one env var was missing
    • Fixes an issue with the sentiment-analysis plugin

    πŸ†• New:

    • PR and Issue template
    Source code(tar.gz)
    Source code(zip)
  • v.1.0.0(Sep 2, 2022)

    After many years of using Hans as the pillar of our Discord community, I decided to make it public & open-source it! Many functionalities and old/guild-specific commands were cleaned out and left everything else to be used as a base.

    πŸ’Ž Features

    • Discord.JS v13.6.0
    • Slash Commands ready!
    • Built with TS
    • Covers main guildEvents (guildMemberAdd, guildMemberRemove, messageDelete, messageUpdate, messageCreate... )
    • Production-ready with easily Docker or K8s deployments.

    πŸ—“ Current slash commands:

    • /weather city -> Weather at specific city
    • /about username -> User details
    • /invite -> Hans invite link
    • /support -> Hans support discord
    • /wifu -> Well, you know what it is :P

    πŸ”Œ Plugins

    Moderation: Sentiment Analysis: Checks message sentiment (positive or negative) and based on the weight, it will notify to a given channel.

    Threads: Creates thread channels. Once a message is created, it will automatically open a thread discussion. This is helpful to keep the channel clean and on-topic (support channels, for example)

    Guild member Activity Can enable a member join/leave channel for activity logs.

    πŸ—Ί Roadmap

    As for the next steps, now that the base it's set, we can start working on improvements and features. The first step will be to open issues (that anyone can contribute to!) to enable guild configuration. Right now, the plugins' functionality can only be done vΓ­a DB editing.

    Once the core functionality is there, new features will be work on.

    πŸ‘₯ Community

    • Feel fee to join the official discord channel: https://discord.gg/WpTrnnvJXe
    • If you have any ideas or you find a bug, open an Issue
    Source code(tar.gz)
    Source code(zip)
Owner
Sorin
Sr. UX Developer. I do things with code | JS
Sorin
Co-Pilot is a discord Bot designed to be the all-in-one, open-source Discord bot that handles all your server needs.

Welcome to Co-Pilot Bot repo! ?? ?? Co-Pilot (All-in-one Discord Bot) Co-Pilot is a discord Bot designed to be the all-in-one, open-source Discord bot

YMafalha 19 Nov 11, 2022
Discord-Bot - You can use the discord bot codes that are updated in every video of the codes I use in the discord bot making series that I have published on my youtube channel.

Discord-Bot You can use the discord bot codes that are updated in every video of the codes I use in the discord bot making series that I have publishe

Umut Bayraktar 114 Jan 3, 2023
Denky is a multipurpose Discord bot used in +3000 servers. Built with Node.js, TypeScript and discord.js.

?? Denky Bot Denky is a brazilian Discord bot, built with Node.js, TypeScript and discord.js. βš™οΈ Self hosting ⚠️ Support will not be provided for self

Denky Labs 19 Dec 26, 2022
Eclipse is a multipurpose Discord bot. Built with Node.js, TypeScript and discord.js.

?? Eclipse Bot Eclipse is a brazilian Discord bot, built with Node.js, TypeScript and discord.js. ?? Self-Hosting ⚠️ Support will not be provided for

Eclipse labs 14 Dec 15, 2022
New base bot WhatsApp 🈴 bukan self bot lagi atau buka bot yang bisa di pakai oleh bot sendiri 😎

Installation β€’ Thanks to β€’ Donate Official Group Bot β€’ Settings Instalasi Heroku Buildpack Click the deploy icon below ! > heroku/nodejs > https://g

zeeone 27 Feb 9, 2022
Meet Muffin - a multipurpose, customizable and open source Discord bot with bunch of useful features for your server!

Meet Muffin - a multipurpose, highly customizable and open source Discord bot with bunch of useful features for your server! Self-hosting notice While

null 0 Oct 21, 2021
An open source community powered Discord bot to stop and remove the trash from the SW workshop.

SW Anti Reuploads & Trash Discord bot An open source community powered Discord bot to stop and remove the trash from the SW workshop. SW Discord Β· Cre

SIMPLE MARK 4 Jun 20, 2022
A Discord Bot For Open Source Guidance & Resources

OSC-Bot A Discord Bot For Open Source Guidance & Resources OSC Bot is an open-source discord bot created using discord.js for providing guidance and r

Aakash Jha 12 Oct 26, 2022
[WIP] Meet Koshiro! Our official Discord Bot, Open Source and Community builded. πŸ›Έ

Koshiro Meet Koshiro! Our official Discord Bot, Open Source and Community builded. ?? Getting Started Clone the repository git clone https://github.co

WebX DAO 5 Nov 19, 2022
Discord Neura - a Discord bot framework built on discord.js

Discord Neura Description Discord Neura is a Discord bot framework built on discord.js. Features Command Handler, Arguments, Preconditions and Listene

Discord Neura 3 Mar 23, 2022
Gitlift Discord Bot is a discord bot which is listening Discord Messages to reply with user gitlift profile and total contributions.

Remoklify - Gitlift Discord Bot Gitlift Discord Bot is a discord bot which is listening Discord Messages to reply with user gitlift profile and total

Remoklify 3 Mar 20, 2022
About Discord bot draft that does not contain ready-made commands, compatible with discord.js v14. Create your own discord bot with this command handler.

discordJS-V14 About Discord bot draft that does not contain ready-made commands, compatible with discord.js v14. Create your own discord bot with this

Umut Bayraktar 36 Dec 28, 2022
It is a discord bot bot which can play lofi song in different language 24/7. It has premium system and cool embed looks with buttons. It can play youtube songs, playlists. This bot code was made by Supreme#2401. It uses djs V12

Lofi-Radio-Music-Bot It is a discord bot bot which can play lofi song in different language 24/7. It has premium system and cool embed looks with butt

Diwas Atreya 89 Jan 2, 2023
An open-source ERIS bot, made by the DashCruft Nation contributors with love <3

ErisCruft-Bot The official community bot for the DashCruft Nation. This time in eris! Requirements & Rules You HAVE to be a member in our Offical Disc

DashCruft-Nation 4 Apr 5, 2022
Whatsapp bot using Bailey multi device module, using nodejs and open source, I accept ideas from public

Allen Bot-Wa Keep copyright, Created by lolhuman | Please read carefully Content Description Example Highlights TODO Installation FAQ Contributing Con

Pais 35 Dec 3, 2022
This bot is a cool Discord bot made in discord.js using Node.JS

Anti-Crosspost Discord Bot This bot is a cool Discord bot made in discord.js using Node.JS. It detects when a user cross-posts a message in multiple c

Muhammad Usman Mithani 4 May 31, 2022
Denky is a multipurpose Discord bot, build with Node.js, TypeScript and discord.js.

?? Denky Bot Denky is a brazilian Discord bot, build with Node.js, TypeScript and discord.js. βš™οΈ How to Create a Discord application. Guide Install No

Davi Patricio 8 Apr 6, 2022
A free NodeJS sniper bot built to work with DxSale. DxLaunch is an open, decentralized platform for token sales.

DxSale sniper bot Purpose This bot allows you to compete with other trading bots when buying a cryptocurrency which is going to be on presale on DxSal

Miroslav Nedelchev 114 Dec 25, 2022
A documentation bot built using slash-create for its documentation, functionality derived from Eris Docs bot.

docs-bot A service that handles navigation of a docgen project manifest. Commands All arguments are required. $ npx slash-up list /docs - Search docu

/create 4 Dec 15, 2022