Skip to content

Stark.inline

Python decorator of class Stark to handle inline queries.

This decorator is used to handle inline queries. All arguments are optional.

Parameters:

Name Type Description Default
query str | list[str]

Query on which your function is called. Pass a list to handle multiple queries. Defaults to None, to handle all queries if your function handles all or if you are using other 'filters'

None
startswith bool

Set to True if you want your function to handle all queries starting with the 'query' string passed. Defaults to False.

False
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
group int

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

0
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 and easiest way.
# Bot will show results / execute function, if 'hello' is searched by anyone.
@Stark.inline('hello')

# Handle multiple inline queries in one function. Mainly used to execute same function or do some other pythonic thing, like if-else loop.
# Bot will show results / execute function, if 'hello' or 'hey' is searched by anyone.
@Stark.inline(['hello', 'hey'])

# Function will only be triggered if owner searches 'hello', that is, the user whose id is set as OWNER_ID in environment variables.
# Others will be ignored.
@Stark.inline('hello', owner_only=True)

# Function will only be triggered if sudo users or owner searches 'hello', that is, users set as SUDO_USERS or OWNER_ID in environment variables.
# Others will be ignored.
@Stark.inline('hello', sudo_only=True)

# Filter/Handle all queries.

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

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

# Don't use this as other functions that handle queries won't work.
@Stark.inline()

# Filter other type of queries using 'filters' argument.

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

# Filter only queries by 'StarkProgrammer' and 'Designatory'.
@Stark.inline(filters=filters.user(['StarkProgrammer', 'Designatory']))

# Filter only queries done in 'StarkBotsChat'
@Stark.inline(filters=filters.chat('StarkBotsChat'))

# Filter only queries ending with the word 'baby'.
@Stark.inline(filters=filters.regex(r'baby$'))

# Filter all queries with the word 'hello' AND which are done in 'StarkBotsChat'.
@Stark.inline(filters=filters.chat('StarkBotsChat') & filters.regex('hello'))
# or
@Stark.inline('hello', filters=filters.chat('StarkBotsChat'))

# Filter all queries with the word 'bots' OR which are done in 'StarkBotsChat'
@Stark.inline(filters=filters.chat('StarkBotsChat') | filters.regex('hello'))

# Filter all queries with the word 'bots' BUT which are NOT done in 'StarkBotsChat'
@Stark.inline(filters=~filters.chat('StarkBotsChat') & filters.regex('hello'))
# or
@Stark.inline(filters=filters.regex('hello') & ~filters.chat('StarkBotsChat'))
Back to top