Skip to main content

Getting scapi

Our main scapi file can be found here. Simply place this file in the folder where you want to program your bot. You can find out how to use scapi in your code below. We also recommend that you take a look at our scapi bot directory to get an overview of how a bot can be structured.

Using scapi in your code

Scapi gets easier with every update. To import Scapi, use Python’s import statement:
We recommend using YAML for configuration files. You can install YAML using pip (pip install pyyaml)

Write your first bot (stbmv1)

This documentation section only applies to Scapi Legacy v1.0.0 (stbmv1) or higher

First steps

To set up the basics of your bot, you need a bot object. You can create this using our bot object class:
In this table you can see all available arguments with their meaning In order for the bot to log in to the server, you need to add an important function

Flags

Flags are an important part of programming your Scapi bot. You need flags to determine, for example, whether you want to see messages from users in your bot logs or whether you want to activate message input within the console. The definition of your flags could look like this:
In this table you can see all available flags with their meaning

Permissions

Another part of your bot are authorizations. These check whether the user who has executed a command also has the necessary authorizations. You can also define who the bot owner is. There is a function in Scapi that accepts user-defined values for authorization management. You can use this function to define the bot owner, or create a custom list and then use it within commands. The owner and a custom list can be defined as follows:

Commands (@commands Module)

In order for the bot to have a purpose, it needs commands. A simple command looks like this:
Scapi has 2 different methods to write a bot. One method is newer and cleaner but is not yet fully developed. This method is called Commands. This part explains how to write a command using the command moduleFor the other method, you can check out this documentation section
To clarify what is meant by what, here is a detailed explanation:

Commands (Original Method)

As you have learned here, Scapi has 2 different methods to write a bot command. This part shows you how to use the other method. This one is a bit more difficult, but can be more customized. This method is still used for pure on_message events to accept & process pure messages.
We recommend using the Commands method as it has more features & support than the original method (e.g. permissions)

Events

There are certain events that the bot can call up when something specific happens. One of these events is called on_ready. This event is called when you start the bot. You only have to pass the on_ready function as an argument to the Bot.run() function. An on_ready event can look like this:

Start the bot

To start the bot, you first need to know which command method you are using.

Example bot (Stable v1.0)

This example bot only applies to scapi legacy v1.0.0 (stbmv1)
The other method is the original. This is more difficult, but can be adapted considerably more. This method is still used for pure on_message events to accept and process pure messages. This method is called Original
We recommend using the command method as it offers more features & more support than the original method (e.g. permissions)
This is an example of what your configuration could look like (YAML)

Write your first bot (stbmv2)

This documentation section only applies to Scapi v0.12.0 (stbmv2) or higher

First steps

To set up the basics of your bot, you need a bot object. You can create this using our bot object class:
In this table you can see all available arguments with their meaning
The argument json is only available since Scapi v0.12.1
The argument prefix is only available since Scapi v0.13.1b2
In order for the bot to log into the server, you need to add an important function

Flags

Flags are an important part of programming your Scapi bot. You need flags to determine, for example, whether you want to see messages from users in your bot logs or whether you want to activate message input within the console. The definition of your flags could look like this:
In this table you can see all available flags with their meaning

Permissions

Another part of your bot are authorizations. These check whether the user who has executed a command also has the necessary authorizations. You can also define who the bot owner is. There is a function in Scapi that accepts user-defined values for authorization management. You can use this function to define the bot owner, or create a custom list and then use it within commands. The owner and a custom list can be defined as follows:

Commands (Commands Module)

In order for the bot to have a purpose, it needs commands. A simple command looks like this:
Scapi has 2 different methods to write a bot. One method is newer and cleaner but is not yet fully developed. This method is called Commands. This part explains how to write a command using the command module.The older method is deprecated since Scapi v0.12.1 and should therefore no longer be used
To clarify what is meant by what, here is a detailed explanation: You can find more commands here

Commands (Original Method)

The official support for the original method has been removed since Scapi v0.12.1.To continue using the original method, we recommend the new @on_message method (since v0.13). If functionality is missing, please open an Issue on our GitHubIf you still want to use this method for whatever reason, please have a look at this part of the documentation

Events

There are certain events that the bot can call up when something specific happens.

@on_message Event

As of Scapi v0.13, we have added an improved version of the original message method. This uses our modern Python standard and Python decorators. The implementation in your bot code is very simple. You only need at least Scapi v0.13 or higher. A bot message event can look like this:
Not all functions of the old original method could be adopted, therefore the @on_message method is more restricted.The following functions could not be implemented so far (but could appear in a different form in the future):
  • Use of .startswith()
  • Recognizing specific words within the message
This feature is currently only used, for example, to process a normal word from a user and reply to it.

@on_ready Event

This event is called when you start the bot. You only have to pass the on_ready function as an argument to the Bot.run() function. An on_ready event can look like this:

Start the bot

To start the bot, you first need to know which command method you are using.

Example bot (v0.12.0 or higher)

This documentation part only applies to scapi v0.12.0 (stbmv2) or higher
Official support for the original method has been removed since Scapi v0.12.1. You can read more about it here
You can get Scapi (@json-communication/@main) here. The following piece of code shows you how to make a simple bot with Scapi (stbmv2)
Changing the value json to False will enable the compatibility mode. Note that this is not yet fully developed