Bottle is a framework designed to make it easy for anyone to start creating Discord bots.
Sending a message is as easy as writing a print statement. For example, here is the code for a command that
prints "Hello, Bottle!"
print('Hello, Bottle!')And here is code for a command to greet the user:
from bottle import user
print("Hello, " + user.name + "!")Commands can be written in any language - simply put the executable in the bot/commands folder.
But we currently only have libraries to make it easier to write bots in JavaScript and Python.
- Clone the repository:
~:$ git clone [email protected]:qrvd/bottle.git- Install the dependencies:
~:$ cd bottle
~:$ npm install- Start the
bottlescript to start running your bot!
~:$ cd bot
~:$ ./bottle.sh # on Linux/macOS
~:$ bottle.bat # on WindowsIn Bottle, your commands are the files in the commands/ folder, feel free
to peek in that folder for examples on how it works.
Whatever is printed by your command, will be sent by the bot after the command finishes running.
Your users' data are stored as simple JSON files, in the users/ folder.
Commands can bd written in any programming language, but feel free to use
the included Python/JS libraries as seen in the example commands (bot/commands).
It allows you to write very simple code. Here is the code for a simple "balance" command:
#!/usr/bin/env python3
from bottle import user
if 'balance' not in user:
user.balance = 0
else:
user.balance = user.balance + 1
print("Your balance is: %s" % user.balance)If you use the Python/JavaScript libraries, all changes to the "user" object will be automatically saved, and kept for the next time the user runs any other command. That is why the above code is all that's needed.
You can run your commands directly from the command-line,
which allows for much easier testing/development! Here is an example
of how to run the balance command from the command-line:
~:$ cd commands
~:$ python balance.py
Your balance is: 0
~:$ python balance.py
Your balance is: 1By default, commands that you run on the command-line will behave as if your bot was the user that ran the command. But sometimes you may want to test them with another user, which can be done simply once you have the user's Discord ID.
# Tell Bottle to run commands from the command-line as if the user "12345678910" ran them.
$ export BOTTLE_USER_ID=12345678910
$ python balance.py
Your balance is: 0
# Return to using the bot's "user":
$ export BOTTLE_USER_ID=bot
$ python balance.py
Your balance is: 2:: Tell Bottle to run commands from the command-line as if the user "12345678910" ran them.
> set BOTTLE_USER_ID=12345678910
> python balance.py
Your balance is: 0
:: Return to using the bot's "user":
> set BOTTLE_USER_ID=bot
> python balance.py
Your balance is: 2