Skip to content

jediswaplabs/discord-alert-bot

Repository files navigation

JediSwap Alert Bot

GitHub Python 3.9+

Preview

A Telegram bot sending out a real time notification each time your handle is mentioned on the JediSwap Discord server. To use, start a conversation with @JediSwapAlertBot on Telegram. This will bring up the bot menu, where you can set up your Discord handle. After entering it and verifying via Discord, the bot will forward any message mentioning your Discord handle or any of your roles to your Telegram. Notifications can be deactivated for any role or channel using the bot menu.

Running the bot on your Discord server

  • Clone this repository.
  • Get a Discord bot token and create an application at the Discord developer portal.
  • At the portal, set the bot up with the permission to view channels and add server members intent and message content intent.
  • Get a Telegram bot token.
  • Rename sample.env to .env and enter the following information to the file without any spaces or quotes (except for quotes around lists and around strings within these lists):
    • DISCORD_TOKEN=your Discord bot token
    • TELEGRAM_BOT_TOKEN=your Telegram bot token
    • OAUTH_DISCORD_CLIENT_ID=your Discord application ID
    • OAUTH_DISCORD_CLIENT_SECRET=your Discord client secret
    • OAUTH_REDIRECT_URI=see 'Discord Authentication' below
    • DEFAULT_GUILD=your Discord server ID
    • ALLOWED_CHANNEL_CATEGORIES='[<channel.id>, <channel.id>, ...]' (enter the category channel IDs containing the channels the user is supposed to see in the bot's channels menu.)
    • ROLES_EXEMPT_BY_DEFAULT='["<role.name>", "<role.name>", ...]' (names of all roles supposed to be active by default if the user possesses them)
    • ALWAYS_ACTIVE_CHANNELS='[<channel.id>, <channel.id>, ...]' (IDs of the channels supposed to be always active for notifications, even for unverified Discord users. This list is intended for an announcements channel for example, which you want to reach everyone with.)
  • Add the bot to your Discord server as shown here or set up an invite link using your client ID (= application ID).
  • Private channels: If the bot does not have a moderator role, he will need to be a member of any private channel the notifications are supposed to work in.
  • Run python main.py.
  • If run for longer periods of time, run nohup python main.py instead.

Requirements & Installation

The bot requires python 3.9 and uses the packages listed in requirements.txt. The best practice would be to install a virtual environment.

  • Install & activate a virtual environment using either venv:

    python -m venv venv
    source venv/bin/activate    # `deactivate` to leave again
    

    or anaconda:

    conda create -n venv python=3.9
    conda activate venv         # `conda deactivate` to leave again
    
  • Install dependencies:

    pip install -r requirements.txt
    

Discord Authentication

This bot uses Oauth2 authentication, which requires a whitelisted redirect url to send back the verification info safely. Sending oauth data back to a Telegram bot instead of a website requires a workaround. To enable users to verify their Discord handle, you can set up an aws api gateway as described here. Add its url to the .env file under OAUTH_REDIRECT_URI=, and don't forget to also add it to the whitelist on the Discord developer portal under Applications -> OAuth2 -> Redirects. These two entered urls need to match exactly.

State Diagram

State Diagram Created with mermaid. Template by the python-telegram-bot team.

License

This project is licensed under the MIT license - see the LICENSE file for details.

About

A Telegram bot that notifies you when your handle is mentioned in a specific Discord server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages