Package: hikari-crescent
hikari-crescent🌙 A command handler forHikarithat keeps your project neat and tidy.FeaturesSimple 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.Easily use a custom context class.Makes typehinting easy.RESTBot and GatewayBot support.Links📦 |Pypi🗃️ |Docs🎨 |Template ProjectInstallationCrescent is supported in python3.8+.pip install hikari-crescentBots using CrescentmCodingBot- The bot for the mCoding Discord server.Starboard 3- A starbord bot by@CircuitSaculin over 17k servers.UsageCrescent usesclass commandsto 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.importcrescentimporthikaribot=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")classSay:word=crescent.option(str,"The word to say")asyncdefcallback(self,ctx:crescent.Context)->None:awaitctx.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.commandasyncdefping(ctx:crescent.Context):awaitctx.respond("Pong!")Adding arguments to the function adds more options. Information for arguments can be provided using theAnnotatedtype hint.
Seethis examplefor more information.# python 3.9 +fromtypingimportAnnotatedasAtd# python 3.8fromtyping_extensionsimportAnnotatedasAtd@client.include@crescent.commandasyncdefsay(ctx:crescent.Context,word:str):awaitctx.respond(word)# The same command but with a description for `word`@client.include@crescent.commandasyncdefsay(ctx:crescent.Context,word:Atd[str,"The word to say"])->None:awaitctx.respond(word)Typing to Option Types Lookup TableTypeOption TypestrTextintIntegerboolBooleanfloatNumberhikari.UserUserhikari.RoleRolecrescent.MentionableRole or UserAny Hikari channel type.Channel. The options will be the channel type and its subclasses.List[Channel Types](classes only)Channel. ^Union[Channel Types](functions only)Channel. ^hikari.AttachmentAttachmentAutocompleteAutocomplete 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, andfloatvalue types
can be used.asyncdefautocomplete(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")classClassCommand:option=crescent.option(str,autocomplete=autocomplete)asyncdefcallback(self)->None:awaitctx.respond(self.option)@client.include@crescent.commandasyncdeffunction_command(ctx:crescent.Context,option:Annotated[str,crescent.Autocomplete(autocomplete)])->None:awaitctx.respond(option)Error HandlingErrors that are raised by a command can be handled bycrescent.catch_command.classMyError(Exception):...@client.include@crescent.catch_command(MyError)asyncdefon_err(exc:MyError,ctx:crescent.Context)->None:awaitctx.respond("An error occurred while running the command.")@client.include@crescent.commandasyncdefmy_command(ctx:crescent.Context):raiseMyError()There is also acrescent.catch_eventandcrescent.catch_autocompletefunction for
events and autocomplete respectively.Eventsimporthikari@client.include@crescent.eventasyncdefon_message_create(event:hikari.MessageCreateEvent):ifevent.message.author.is_bot:returnawaitevent.message.respond("Hello!")Using crescent's event decorator lets you use
crescent'sevent error handling system.ExtensionsCrescent 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!SupportYou can ask questions in the#crescentchannel in theHikari Discord server. My Discord username islunarmagpie.ContributingCreate an issue for your feature. There aren't any guidelines right now so just don't be rude.