Skip to main content

Discord-Notifier-Bot

GitHub release GitHub code size in bytes MHTML License PyPI supported Python versions Code style: black

A simple python Discord bot to send messages to Discord channel via command line.

It allows markdown formatted messages and attaching files.

It registers the following commands:

  • dbot-run - main CLI entry-point

  • dbot-message - (short-hand) to send a message, or even pipe - message contents

  • dbot-file - (short-hand) to send a file with an message

Requirements

  • Python >= 3.6 (see badges above) (Python 3.5.3 would technically be possible, but does not support PEP 498 f-Strings, so a large portion of the string formatting would need rewrites.)

  • discord.py

Installation

python3 -m pip install discord-notifier-bot

Optionally, install it locally with --user.

Configuration

Configuration is done by placing a .dbot.conf file in one of the following directories:

  • $HOME/.dbot.conf

  • $HOME/dbot.conf

  • ./.dbot.conf

  • ./dbot.conf

  • /etc/dbot.conf

Alternatively a configuration file can be provided via -c/--config CLI options.

The configuration file should be a standard INI file. A template can be found in the templates folder. All configurations are placed under the discord-bot section.

Example:

[discord-bot]
# the bot token (used for login)
token = abc
# the numeric id of a channel, can be found when activating the developer options in appearances
channel = 123

Usage

dbot-message and dbot-file are simpler versions of dbot-run.

Print help and available options:

dbot-run -h

Sending messages:

# send a simple message
dbot-run message "Test message"
# or shorter:
dbot-message "Test **message**"

# pipe output
echo "Test" | dbot-emessage -

# wrap it inside a code-block ```
# optionally with a type
cat `which dbot-message` | dbot-message - --type
cat `which dbot-message` | dbot-message - --type python

Sending a file:

dbot-file README.rst "Your message to desribe the attached file"
# or with no visible message:
dbot-file README.rst ""

# optionally also like this:
dbot-run file -f README.rst "Message ..."

You are always able to specify the configuration file like this:

dbot-run -c /path/to/dbot.conf [...]
dbot-{message,file} -c /path/to/dbot.conf [...]

Only with dbot-run: To display debugging information (api calls, log messages etc.):

dbot-run -d [...]

You may also run the bot with the python module notation. But it will only run the same entry-point like dbot-run.

python -m discord_notifier_bot [...]

Full CLI help message:

usage: dbot-run [-h] [--type [TYPE]] [-f FILE] [-c CONFIG] [-d]
                {message,file} message

positional arguments:
  {message,file}        Bot action
  message               Message to send

optional arguments:
  -h, --help            show this help message and exit
  --type [TYPE]         Markdown type for text messages, or default if as flag
  -f FILE, --file FILE  Optional file to attach to message
  -c CONFIG, --config CONFIG
                        Config file
  -d, --debug           Enable debug logging
usage: dbot-file [-h] [-c CONFIG] file message

positional arguments:
  file
  message

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        Config file
usage: dbot-message [-h] [-c CONFIG] [--type [TYPE]] message

positional arguments:
  message

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        Config file
  --type [TYPE]         Markdown type, or default if without value

Embedded in other scripts

Sending messages is rather straightforward. More complex examples can be found in the CLI entrypoints, see file discord_notifier_bot.cli. Below are some rather basic examples (extracted from the CLI code).

Basic setup (logging + config loading):

from discord_notifier_bot.cli import setup_logging, load_config

# logging (rather basic, if needed)
setup_logging(True)

# load configuration file (provide filename or None)
configs = load_config(filename=None)

Sending a message:

from discord_notifier_bot.bot import send_message

# message string with basic markdown support
message = "The **message** to `send`"
# bot token and channel_id (loaded from configs or hard-coded)
bot_token, channel_id = configs["token"], configs["channel"]
# send the message
send_message(bot_token, channel_id, message)

Bot Creation etc.

See information provided by:

Short description

You have to own a Discord server! Or know someone with administrator/moderation(?) privileges.

  1. Visit and login to the Discord developer page.

  2. Create a new application. The given name is also the visible name of the bot. (default, can be changed later?)

  3. Create a bot (on the Bot page). You should disable the Public Bot option.

    • The bot login token (credentials) can be found on the Bot page.

  4. Change to the OAuth2 page and check

    • Scopes: Bot

    • Bot Permissions: Send Messages, Attach Files (in the Text Permissions column)

  5. Copy the URL in the Scopes section and paste it in a new browser tab.

    • Now you can choose one (?) of your own Discord servers to add the bot to. (For this you need server administration permissions, or be the owner..?)

To get the channel id, send the following message on your server \#channelname, or enable developer options. You may want to visit the following pages for more information:

Credits

Metadata

Release files for discord-notifier-bot 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for discord-notifier-bot 0.3.3
File Size Uploaded Provenance
discord-notifier-bot-0.3.3.tar.gz 7.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for discord-notifier-bot 0.3.3
File Interpreter ABI Platform
discord_notifier_bot-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / discord-notifier-bot-0.3.3.tar.gz

Download URL discord-notifier-bot-0.3.3.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2d6620507a722be2bb94b2bca077d663cfa24fbe2681f33304dd60f5ddc92645
BLAKE2b-256 checksum
How to use checksums
55bc1a10dc83ef86b41d1caf133cf00d3f3c031a59261626a584f058507756c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

Release files / discord_notifier_bot-0.3.3-py3-none-any.whl

Download URL discord_notifier_bot-0.3.3-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8742102da8fdc9991d268e328823afc14de9d54642f94c80f22fe1e9a1ab569
BLAKE2b-256 checksum
How to use checksums
a0c44fd1a2d3e3918c39110460f521f6324f68389e1da38a74c4df5c34c53183
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

Security for discord-notifier-bot 0.3.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page