hikari-crescent
🌙 A command handler for Hikari that keeps your project neat and tidy.
Features
- Simple and intuitive API.
- Slash, user, and message commands.
- Command localization.
- Error handling for commands, events, and autocomplete.
- Hooks to run function before or after a command (or any command from a group!)
- Plugin system to easily split bot into different modules.
- Makes typehinting easy.
- RESTBot and GatewayBot support.
Links
📦 | Pypi
🗃️ | Docs
🎨 | Template Project
Installation
Crescent is supported in python3.9+.
pip install hikari-crescent
Bots using Crescent
- mCodingBot - The bot for the mCoding Discord server.
- Starboard 3 - A starbord bot by @CircuitSacul in over 17k servers.
Usage
Crescent uses class commands to simplify creating commands. Class commands allow you to create a command similar to how you declare a dataclass. The option function takes a type followed by the description, then optional information.
import crescent
import hikari
bot = hikari.GatewayBot("YOUR_TOKEN")
client = crescent.Client(bot)
# Include the command in your client - don't forget this
@client.include
# Create a slash command
@crescent.command(name="say")
class Say:
word = crescent.option(str, "The word to say")
async def callback(self, ctx: crescent.Context) -> None:
await ctx.respond(self.word)
bot.run()
Simple commands can use functions instead of classes. It is recommended to use a function when your command does not have any options.
@client.include
@crescent.command
async def ping(ctx: crescent.Context):
await ctx.respond("Pong!")
Typing to Option Types Lookup Table
| Type | Option Type |
|---|---|
str |
Text |
int |
Integer |
bool |
Boolean |
float |
Number |
hikari.User |
User |
hikari.Role |
Role |
crescent.Mentionable |
Role or User |
| Any Hikari channel type. | Channel. The options will be the channel type and its subclasses. |
List[Channel Types] |
Channel. ^ |
hikari.Attachment |
Attachment |
Autocomplete
Autocomplete is supported by using a callback function. This function returns a list of tuples where the first
value is the option name and the second value is the option value. str, int, and float value types
can be used.
async def autocomplete(
ctx: crescent.AutocompleteContext, option: hikari.AutocompleteInteractionOption
) -> list[tuple[str, str]]:
return [("Option 1", "Option value 1"), ("Option 2", "Option value 2")]
@client.include
@crescent.command(name="class-command")
class ClassCommand:
option = crescent.option(str, autocomplete=autocomplete)
async def callback(self) -> None:
await ctx.respond(self.option)
Error Handling
Errors that are raised by a command can be handled by crescent.catch_command.
class MyError(Exception):
...
@client.include
@crescent.catch_command(MyError)
async def on_err(exc: MyError, ctx: crescent.Context) -> None:
await ctx.respond("An error occurred while running the command.")
@client.include
@crescent.command
async def my_command(ctx: crescent.Context):
raise MyError()
There is also a crescent.catch_event and crescent.catch_autocomplete function for
events and autocomplete respectively.
Events
import hikari
@client.include
@crescent.event
async def on_message_create(event: hikari.MessageCreateEvent):
if event.message.author.is_bot:
return
await event.message.respond("Hello!")
Using crescent's event decorator lets you use crescent's event error handling system.
Extensions
Crescent has 3 builtin extensions.
- crescent-ext-cooldowns - Allows you to add sliding window rate limits to your commands.
- crescent-ext-locales - Contains classes that cover common use cases for localization.
- crescent-ext-tasks - Schedules background tasks using loops or cronjobs.
These extensions can be installed with pip.
- crescent-ext-docstrings - Lets you use docstrings to write descriptions for commands and options.
- crescent-ext-kebabify - Turns your command names into kebabs!
Support
You can ask questions in the #crescent channel in the Hikari Discord server. My Discord username is lunarmagpie.
Contributing
Create an issue for your feature. There aren't any guidelines right now so just don't be rude.
Metadata
Release files for hikari-crescent 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hikari_crescent-1.4.0.tar.gz | 42.0 kB | Without provenance | Details for hikari_crescent-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hikari_crescent-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for hikari_crescent-1.4.0-py3-none-any.whl |
Total release size: 97.4 kB
Release files / hikari_crescent-1.4.0.tar.gz
| Download URL | hikari_crescent-1.4.0.tar.gz |
|---|---|
| Size | 42.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab34ddbddecf1586c256c0ed44847b9758247a04e5ce081765b4721325e8db82
|
|
BLAKE2b-256 checksum How to use checksums |
c26c28a08bb11120447464135353d6202f1ddb161207fb9fcad6e240a5c7fb5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.10.19 Linux/6.11.0-1018-azure
|
Release files / hikari_crescent-1.4.0-py3-none-any.whl
| Download URL | hikari_crescent-1.4.0-py3-none-any.whl |
|---|---|
| Size | 55.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9618c90a438563bb1e34d68dc363cd37f827c42a25a316d9fe7f02f3f3901757
|
|
BLAKE2b-256 checksum How to use checksums |
553c899de8b4258c182599a5ff97973876d496be86be0aa75b92396f3e3c5ed4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.10.19 Linux/6.11.0-1018-azure
|
Security for hikari-crescent 1.4.0
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.