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’simport statement:
Write your first bot (stbmv1)
First steps
To set up the basics of your bot, you need a bot object. You can create this using our bot object class:| Flag | Erklärung |
|---|---|
username | The user name of the bot |
token | The token (password) of the bot |
host | Remote server where the bot should connect to |
port | The port of the remote server |
enable_user_input | Activate message input within the console (Also available as a flag) |
print_recv_msg | Output received messages to the bot logs (console) (Also available as a flag) |
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:| Flag | Explanation |
|---|---|
print_recv_msg | Output received messages to the bot logs (console) |
enable_user_input | Activate message input within the console |
log_msg | Change the format of the log messages |
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| Code | Explanation |
|---|---|
name | Stands for the command name, which is then added to the registry. You can then call up the command using the prefix and then the name (e.g. !test) |
arg_count | Number of arguments that the command accepts and requires as a minimum. A lower number can also be specified and more arguments can still be accepted |
required_permissions | Required authorization for the command. A value of the Scapi class must be transferred here. Scapi.Bot.PermissionLevel.CUSTOM for the custom list that you have defined here |
username | The user name of the user who executed the command |
args | The arguments that were passed when the command was executed. Is saved in a list (["first", "second", "third"]) |
send_message(...) | Function to send a message |
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 pureon_message
events to accept & process pure messages.
Events
There are certain events that the bot can call up when something specific happens. One of these events is calledon_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)
The other method is the original. This is more difficult, but can be adapted considerably more. This method is still used for pureon_message events to accept and process pure messages.
This method is called Original
Write your first bot (stbmv2)
First steps
To set up the basics of your bot, you need a bot object. You can create this using our bot object class:| Flag | Erklärung |
|---|---|
username | The user name of the bot |
token | The token (password) of the bot |
host | Remote server where the bot should connect to |
prefix | The prefix of the bot to which it should listen (e.g. !help) |
port | The port of the remote server |
enable_user_input | Activate message input within the console (Also available as a flag) |
print_recv_msg | Output received messages to the bot logs (console) (Also available as a flag) |
json | Activates or deactivates the compatibility mode for old servers |
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:| Flag | Explanation |
|---|---|
print_recv_msg | Output received messages to the bot logs (console) |
enable_user_input | Activate message input within the console |
log_msg | Change the format of the log messages |
ignore_capitalization | Activates or deactivates the ignoring of capital letters for the on_message method (only available from Scapi v0.13) |
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| Code | Explanation |
|---|---|
name | Stands for the command name, which is then added to the registry. You can then call up the command using the prefix and then the name (e.g. !test) |
arg_count | Number of arguments that the command accepts and requires as a minimum. A lower number can also be specified and more arguments can still be accepted |
required_permissions | Required authorization for the command. A value of the Scapi class must be transferred here. Scapi.Bot.PermissionLevel.CUSTOM for the custom list that you have defined here |
username | The user name of the user who executed the command |
args | The arguments that were passed when the command was executed. Is saved in a list (["first", "second", "third"]) |
send_message(...) | Function to send a message |
Direct messages
Direct messages
Leave the chat
Leave the chat
Commands (Original Method)
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:@on_ready Event
This event is called when you start the bot. You only have to pass theon_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)
You can get Scapi (@json-communication/@main) here.
The following piece of code shows you how to make a simple bot with Scapi (stbmv2)
json to False will enable the compatibility mode. Note that this is not yet fully developed