Skip to content

Stark.command

The main python decorator of class Stark.

This decorator is used to handle messages. Mainly used to create commands. All arguments are optional. You can also use the alias Stark.cmd instead of Stark.command.

Parameters:

Name Type Description Default
cmd str | list[str]

Command(s) that triggers your function. Defaults to None, which is helpful you only want to use extra_filters argument.

None
description str, optional

Command description to create Bot Menu. Defaults to None. Read More

None
group int

Define a group for this handler. Defaults to 0. Read More

0
owner_only bool

Allow only owner to use this command. Defaults to False.

False
sudo_only bool

Allow only sudos to use this command. Includes owner as sudo automatically. Defaults to False.

False
private_only bool

Only handle messages for private chats. Bot will ignore messages in groups and channels. Defaults to False.

False
group_only bool

Only handle messages for groups. Bot will ignore messages in private chats and channels. Defaults to False.

False
channel_only bool

Only handle messages for channels. Bot will ignore messages in private chats and groups. Defaults to False.

False
extra_filters pyrogram.filters

Extra filters to apply in your function. Import filters from pyrogram or pystark to use this. See example below.

None

Examples:

from pystark import Stark

# The normal way. Bot will reply to command ``/greet`` sent anywhere and by anyone.
@Stark.command('greet', description='Greet the user')

# or
@Stark.cmd('greet', 'Greet the user')

# Bot will reply only to owner, that is, the user whose id is set as OWNER_ID in environment variables.
# Others will be ignored.
@Stark.command('greet', owner_only=True)

# Bot will reply only to sudo users or owner, that is, users set as SUDO_USERS or OWNER_ID in environment variables.
# Others will be ignored.
@Stark.command('greet', sudo_only=True)

# Bot will reply only if message is sent in private chat (aka pm).
# Messages in groups and channels will be ignored.
@Stark.command('greet', private_only=True)

# Bot will reply only if message is sent in groups.
# Messages in groups and private chats will be ignored.
@Stark.command('greet', group_only=True)

# Bot will reply only if message is sent in channels.
# Messages in private chats and groups will be ignored.
@Stark.command('greet', channel_only=True)


# Filter all messages.

# Use positive integer to execute after executing another function in default group that also filtered this message.
@Stark.command(group=1)

# or Use negative integer to execute before executing another function in default group that also filtered this message.
@Stark.command(group=-1)

# Don't use this as other functions won't work.
@Stark.command()


# Filter other type of messages using extra_filters.

# Import filters from pyrogram or pystark.
from pystark import filters

# Filter only media messages.
@Stark.command(extra_filters=filters.media)

# Filter only text messages.
@Stark.command(extra_filters=filters.text)

# Filter only messages sent by 'StarkProgrammer'.
@Stark.command(extra_filters=filters.user('StarkProgrammer'))

# Filter only messages sent in 'StarkBotsChat'
@Stark.command(extra_filters=filters.chat('StarkBotsChat'))

# Filter only messages with the word 'baby'.
@Stark.command(extra_filters=filters.regex('baby'))

# Filter all media messages sent by bots.
@Stark.command(extra_filters=filters.bot & filters.media)

# Filter all messages sent by bots except media messages.
@Stark.command(extra_filters=filters.bot & ~filters.media)

# Filter either media messages or text messages.
@Stark.command(extra_filters=filters.text | filters.media)
Back to top