Skip to main content

Discord Amethyst

An opinionated extension for discord.py, inspired by JellyCommands. Amethyst adds a handful of features that I found myself re-implementing or wanting for many of my Discord bots such as automatic app command synchronisation and job scheduling.

Widgets

Command & Context Menus

The amethyst command and context_menu decorators are just a wrappers around discord.py's decorators. Please refer to the discord.py documentation for usage.

Event

Amethyst's event decorator is a type hinted wrapper around discord.py's normal event decorator. The primary difference is that you must specify which event you wish to subscribe to. The amethyst module exports all of the default discord.py events with the prefix on_.

import amethyst

@amethyst.event(amethyst.on_ready)
async def on_ready():
    print("Bot is ready!")

Schedule

Amethyst implements a cron-like asynchronous scheduler for calling functions on a set schedule, powered by croniter.

The following is an example of a schedule that will run every day at 8 am.

import amethyst

@amethyst.schedule("0 8 * * *")
async def every_morning():
    print("Good morning!")

Dynamic Module Import

Amethyst can dynamically load python modules, powered by dynamicpy. When run, the client will automatically import and register any widgets found in the .command, .commands, .plugin and .plugins submodules. The submodules which are searched can be configured in the amethyst.Client constructor.

Lets say you have the following project structure:

my-bot/
├── __init__.py
├── main.py
└── commands/
    ├── __init__.py
    ├── foo.py
    └── bar.py

If your instance of amethyst.Client is instantiated in main.py then the commands/ package will be recursively searched for widgets to register.

The searched modules can also be top-level, the only requirement is that they are at the same level as the module inside which the client was instantiated.

my-bot.py
plugins.py
commands/
├── __init__.py
├── foo.py
└── bar.py

In this example, the commands.py module and the commands/ package will be searched.

Plugin System

Amethyst has a plugin system, powered by dynamicpy and inspired by discord.py Cogs. You can create a plugin by simply defining a class that extends amethyst.Plugin. If this is found by the Dynamic Module Importer then it will be automatically registered to the client, otherwise you will have to use the Client.register_plugin method.

An example plugin may look like the following:

import amethyst

class ExamplePlugin(amethyst.Plugin):

    @amethyst.event(amethyst.on_ready)
    async def on_ready(self):
        channel = self.client.get_channel(000000000000000000)
        await channel.send("Bot is ready!")

Plugin Dependency Injection

Amethyst plugins support dynamicpy dependency injection for their constructors. You can add dependencies to the client using the Client.add_dependency method, which will then be injected into constructor parameters when the plugin is registered.

import mysql.connector
import amethyst

client = amethyst.Client(...)
database: mysql.connector.MySQLConnection = mysql.connector.connect(...)
client.add_dependency(database)

class ExamplePlugin(amethyst.Plugin):

    def __init__(self, database: mysql.connector.MySQLConnection) -> None:
        self.database = database

Evironment Variables

Amethyst uses python-dotenv to load .env files found at the project root. This can be used to configure certain aspects of the library.

Name Default Description
AMETHYST_TOKEN None If present, token can be omitted from the Client.run and this will be used instead.
AMETHYST_AUTO_SYNC true If present, the client will synchronise app_commands if they are out of date with Discord.
AMETHYST_GUILD None If present, the client will ignore all events from any guild with a differnet id.

Roadmap

  • Hybrid Commands
  • Debug mode featuring automatic reload

Release files for discord-amethyst 2.0.0

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-amethyst 2.0.0
File Size Uploaded
discord_amethyst-2.0.0.tar.gz 23.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for discord-amethyst 2.0.0
File Interpreter ABI Platform
discord_amethyst-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.3 kB

Release files / discord_amethyst-2.0.0.tar.gz

Download URL discord_amethyst-2.0.0.tar.gz
Size 23.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4d4add693d306de8d9993ab2b58e26897e9c80578c4c32088858aefc16aff8fe
BLAKE2b-256 checksum
How to use checksums
2f54af8726c9fd61be14b2910f669f82dd44aebcd1177a19983e8628043d21b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / discord_amethyst-2.0.0-py3-none-any.whl

Download URL discord_amethyst-2.0.0-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2780be8b8c121fbc3e138fd591f95d25e3f1969dd62cc907b87139d1780d6a62
BLAKE2b-256 checksum
How to use checksums
12c4870ecf35ef1040e96ef3cac020cb3569510c46eb1b654bcd7d5c477e2de6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

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