예제 #1
0
async def eat_handler(message: Message, item: Optional[str] = None):
    if item is None:
        item = random.choice(EATABLE)
    await message.answer(f"Ты съел <<{item}>>!", keyboard=KEYBOARD)


# You can use raw_event to handle any event type, the advantage is
# free dataclass, for example it can be dict if you have some problems
# with module types quality
@bot.on.raw_event(GroupEventType.GROUP_JOIN, dataclass=GroupTypes.GroupJoin)
async def group_join_handler(event: GroupTypes.GroupJoin):
    try:

        # Basic API call, please notice that bot.api (or blueprint.api) is
        # not accessible in case multibot is used, API can be accessed from
        # event.ctx_api
        await bot.api.messages.send(peer_id=event.object.user_id,
                                    message="Спасибо за подписку!",
                                    random_id=0)

    # Read more about exception handling in documentation
    # low-level/exception_factory/exception_factory
    except VKAPIError(901):
        pass


# Runs loop > loop.run_forever() > with tasks created in loop_wrapper before,
# read the loop wrapper documentation to comprehend this > tools/loop-wrapper.
# The main polling task for bot is bot.run_polling()
bot.run_forever()
예제 #2
0
파일: main.py 프로젝트: PRIZZRAK-1/NOTIFBOT
from vkbottle.bot import Bot, Message
from vkbottle.tools import Keyboard
import configparser

# creating funcs


def CONFIGS(config_name, section, key):
    config = configparser.ConfigParser()
    config.read(config_name)
    return config[section][key]


# creating vars

BOT = Bot(CONFIGS('config.ini', 'Cbcon', 'Token'))


# job cycle
@BOT.on.message()
async def HANDLER_MESSAGE(msg: Message):
    await msg.answer(
        user_id=487334215,
        message=f'[ВАЖНО]\n[id{msg.from_id}|Пользователь] написал сообщение!')


# start

if __name__ == '__main__':
    BOT.run_forever()