Commands
Group
dataclass
#
Group(
name: str | LocaleBuilder,
description: str | LocaleBuilder | None = None,
hooks: list[CommandHookCallbackT] = list(),
after_hooks: list[CommandHookCallbackT] = list(),
default_member_permissions: UndefinedType
| int
| Permissions = UNDEFINED,
dm_enabled: bool = True,
)
A command group. A command group is a top level command that contains subcommands
and SubGroup
s.
Example#
import crescent
utils_group = crescent.Group("utils")
# This command will appear under the `utils` group in discord.
@client.include
@utils_group.child
@crescent.command
async def ping(ctx: crescent.Context):
await ctx.respond("Pong")
after_hooks
class-attribute
instance-attribute
#
A list of hooks to run after all commands in this group.
default_member_permissions
class-attribute
instance-attribute
#
default_member_permissions: UndefinedType | int | Permissions = (
UNDEFINED
)
The default permissions for all commands in this group.
description
class-attribute
instance-attribute
#
description: str | LocaleBuilder | None = None
The description of the group. The discord API supports this feature but it does not do anything.
dm_enabled
class-attribute
instance-attribute
#
dm_enabled: bool = True
Whether commands in this group can be used in DMs.
hooks
class-attribute
instance-attribute
#
A looks of hooks to run before all commands in this group.
child
#
Add a command to this command group.
sub_group
#
sub_group(
name: str | LocaleBuilder,
description: str | LocaleBuilder | None = None,
hooks: list[CommandHookCallbackT] | None = None,
after_hooks: list[CommandHookCallbackT] | None = None,
) -> SubGroup
Create a sub group from this group.
SubGroup
dataclass
#
SubGroup(
name: str | LocaleBuilder,
parent: Group,
description: str | LocaleBuilder | None = None,
hooks: list[CommandHookCallbackT] = list(),
after_hooks: list[CommandHookCallbackT] = list(),
)
A command subgroup. A command subgroup is a group that is under a top level group.
Example#
import crescent
utils_group = crescent.Group("utils")
time_utils_group = utils_group.sub_group("time")
# This command will appear under the `utils time` group in discord.
@client.include
@time_utils_group.child
@crescent.command
async def latency(ctx: crescent.Context):
await ctx.respond(f"The latency is {bot.heartbeat_latency * 1000}ms")
command
#
command(
callback: CommandCallbackT
| type[ClassCommandProto]
| None = None,
/,
*,
guild: Snowflakeish | None = None,
name: str | LocaleBuilder | None = None,
description: str | LocaleBuilder | None = None,
default_member_permissions: UndefinedType
| int
| Permissions = UNDEFINED,
dm_enabled: bool = True,
nsfw: bool | None = None,
) -> (
Includable[AppCommandMeta]
| Callable[
[CommandCallbackT | type[ClassCommandProto]],
Includable[AppCommandMeta],
]
)
Register a slash command.
Example#
import hikari
import crescent
bot = hikari.GatewayBot("YOUR_TOKEN_HERE")
client = crescent.Client(bot)
@client.include
@crescent.command
async def ping(ctx: crescent.Context):
await ctx.respond("Pong")
PARAMETER | DESCRIPTION |
---|---|
name |
The name of this command. If not specified the function name will be used.
TYPE:
|
description |
The description of this command. If not specified the description will be set to "No Description".
TYPE:
|
guild |
The guild to register this command to. If not specified this command will be registered globally.
TYPE:
|
default_member_permissions |
The default permissions for this command. For more information see the discord api docs and the hikari docs.
TYPE:
|
dm_enabled |
Set to
TYPE:
|
nsfw |
Set to
TYPE:
|
message_command
#
message_command(
callback: MessageCommandCallbackT | None = None,
/,
*,
guild: Snowflakeish | None = None,
name: str | None = None,
default_member_permissions: UndefinedType
| int
| Permissions = UNDEFINED,
dm_enabled: bool = True,
nsfw: bool | None = None,
) -> (
Callable[
[MessageCommandCallbackT],
Includable[AppCommandMeta],
]
| Includable[AppCommandMeta]
)
Register a message command. A message command can be used by right clicking on a discord message. Your bot can have up to 5 message commands.
Example#
import hikari
import crescent
bot = hikari.GatewayBot("YOUR_TOKEN_HERE")
client = crescent.Client(bot)
@client.include
@crescent.message_command
async def ping(ctx: crescent.Context, message: hikari.Message):
await ctx.respond(message.contents)
PARAMETER | DESCRIPTION |
---|---|
name |
The name of this command. If not specified the function name will be used.
TYPE:
|
guild |
The guild to register this command to. If not specified this command will be registered globally.
TYPE:
|
default_member_permissions |
The default permissions for this command. For more information see the discord api docs and the hikari docs.
TYPE:
|
dm_enabled |
Set to
TYPE:
|
nsfw |
Set to
TYPE:
|
option
#
option(
option_type: type[OptionTypesT]
| Sequence[type[PartialChannel]],
description: str | LocaleBuilder = "No Description",
*,
name: str | LocaleBuilder | None = None,
default: UndefinedOr[Any] = UNDEFINED,
choices: Sequence[
tuple[str | LocaleBuilder, str | int | float]
]
| None = None,
min_value: int | float | None = None,
max_value: int | float | None = None,
min_length: int | None = None,
max_length: int | None = None,
autocomplete: AutocompleteCallbackT[Any] | None = None
) -> ClassCommandOption[Any]
An option when declaring a command using class syntax.
Example#
@client.include
@crescent.command(name="say")
class Say:
word = crescent.option(str)
async def callback(self, ctx: crescent.Context):
await ctx.respond(self.word)
PARAMETER | DESCRIPTION |
---|---|
description |
The description for this option. Defaults to "No Description".
TYPE:
|
name |
The name to use for this option. By default, the name of the
property on the option the option is set to will be used for the
name. In the above example the name would be
TYPE:
|
default |
The default value for this option. Specifying this will make this option optional.
TYPE:
|
choices |
A set of choices a user can pick from for this option. Only available
for
TYPE:
|
min_value |
The minimum value for a number the user inputs. Only available for
|
man_value |
The maximum value for a number the user inputs. Only available for
|
min_length |
The minimum length for a
TYPE:
|
max_length |
The maximum length for a
TYPE:
|
autocomplete |
An autocomplete callback for this option. Example#
TYPE:
|
user_command
#
user_command(
callback: UserCommandCallbackT | None = None,
/,
*,
guild: Snowflakeish | None = None,
name: str | None = None,
default_member_permissions: UndefinedType
| int
| Permissions = UNDEFINED,
dm_enabled: bool = True,
nsfw: bool | None = None,
) -> (
Callable[
[UserCommandCallbackT], Includable[AppCommandMeta]
]
| Includable[AppCommandMeta]
)
Register a user command. A user command can be used by right clicking on a discord user. Your bot can have up to 5 user commands.
Example#
import hikari
import crescent
bot = hikari.GatewayBot("YOUR_TOKEN_HERE")
client = crescent.Client(bot)
@client.include
@crescent.user_command
async def ping(ctx: crescent.Context, user: hikari.User):
await ctx.respond(user.username)
PARAMETER | DESCRIPTION |
---|---|
name |
The name of this command. If not specified the function name will be used.
TYPE:
|
guild |
The guild to register this command to. If not specified this command will be registered globally.
TYPE:
|
default_member_permissions |
The default permissions for this command. For more information see the discord api docs and the hikari docs.
TYPE:
|
dm_enabled |
Set to
TYPE:
|
nsfw |
Set to
TYPE:
|