Skip to content
Kamuri Amorim edited this page Oct 6, 2022 · 1 revision

Welcome to the ICQBotPy wiki!

Installation

Using PIP

You can install it using pip: pip install icqbotpy.

Quick start

Simple echo bot

First, let's do the necessary imports:

from ICQBot import ICQBot, Dispatcher, executor
from ICQBot.messages import ReceivedMessage

Now initialize the bot and dispatcher instances. You can get a token from @metabot.

bot = ICQBot("TOKEN")
dp = Dispatcher(bot)

Next, let's create a command! We will start with a simple /start:

@dp.message_handler(commands="/start")
async def start(message: ReceivedMessage):
    return await message.reply("Hello! I'm a simple bot!")

To create a command that echoes every text message sent to the bot:

@dp.message_handler()
async def echo(message: ReceivedMessage):
    await message.reply(message.text)

Easy, isn't it? Now, to run the bot, just add this to the end of your file:

if __name__ == "__main__":
    executor(dp)

Full code:

from ICQBot import ICQBot, Dispatcher, executor
from ICQBot.messages import ReceivedMessage

bot = ICQBot("TOKEN")
dp = Dispatcher(bot)


@dp.message_handler(commands="/start")
async def start(message: ReceivedMessage):
    return await message.reply("Hello! I'm a simple bot!")


@dp.message_handler()
async def echo(message: ReceivedMessage):
    await message.reply(message.text)


if __name__ == "__main__":
    executor(dp)

You can see more examples on this file.

Clone this wiki locally