Rule Kinds
You can declare rules for handling messages, commands, or other actions. Note that if an event satisfies multiple rules, all of them will activate.
Receiving messages
python
@bot.private_message()
async def f():
return 'I received a private message'
python
@bot.group_message()
async def f():
return 'I received a message in a group'
python
@bot.channel_message()
async def f():
return 'I received a message in a channel'
Receiving commands
python
@bot.private_commands.hello()
async def f():
return 'I received /hello in PM'
python
@bot.group_commands.hello()
async def f():
return 'I received /hello in a group'
Handling group actions
python
@bot.added_to_group()
async def f():
return 'Someone added me to a group'
python
@bot.removed_from_group()
async def f():
pass # The bot was removed from a group
python
@bot.group_became_supergroup()
async def f():
return 'This group has just became supergroup'
Supporting inline mode
python
@bot.inline_query()
async def f():
pass # Someone used an inline mode
Full example for inline mode
python
from folds import Query
@bot.inline_query()
async def f(query: Query):
await query.answer([
query.builder.article('Option A', text='This is some text'),
query.builder.article('Option B', text='This is another text'),
])
Combined rule kinds
You may combine the decorators to declare some common logic:
python
@bot.group_command.help()
@bot.private_command.help()
async def f():
return 'I will always help you'
Custom events
In case you need a specific Telegram event not mentioned above, Folds supports Telethon events:
python
from telethon import events
@bot.on(events.CallbackQuery())
async def f():
...