unb-api-py allows python developers to use the UnbelievaBoat Discord bot API in their own projects! Here's how to get started:
(documentation is coming not-so-soon)
- Install the library
pip install unbapi
- Create an UnbelievaBoat Application at https://unbelievaboat.com/applications and copy the token (keep this secret)
- Import the library, and create an
Application
object. Example:
import unbapi
unbapp = unb.Application("put the token here from step 2.")
You've now created an Application
object. This allows you to get or fetch a guild object. Here's how to get a guild object:
guild = unbapp.get_guild(guild-id)
This will create PartialGuild
object. This allows you to do every action in the guild but doesn't have much information about the app. If you need guild information, such as the name, icon, currency symbol, etc then you should use unbapp.fetch_guild
which gives a Guild
object. However, fetching information is slower then 'getting' it.
A PartialGuild
, or Guild
object allows you to do things inside of a guild (as long as you have permission), such as: fetching a user's balance (and changing it), getting store items, adding/removing items from user's inventories, and more. Here's how to do each:
permissions = guild.fetch_permissions()
print(permissions.economy, permissions.items)
user = guild.fetch_user(user-id)
print(user.cash, user.bank, user.total, user.rank)
This example will add 400 cash to their balance, and remove -100 bank from their bank balance.
user.update_balance(cash=400, bank=-100)
This example set the users cash to 1000, and their bank balance to infinity
import math
user.set_balance(cash=1000, bank=math.inf)
for item in user.fetch_inventory():
print(item.name, item.id, item.quantity)
user.fetch_item_quantity(item-id)
(check out getting an item ID below)
user.add_item(item-id, quantity=1)
(check out getting an item ID below)
user.remove_item(item-id, quantity=1)
(check out getting an item ID below)
for user in user.fetch_leaderboard():
print(user.id, user.rank, user.total)
for item in user.fetch_items():
print(item.name, item.id, item.price)
item.delete()
Editing guild items will come some time in the future.
The library may raise these exceptions:
unbapiException
Base exception for the library
NotFound
The resource couldn't be found
InvalidToken
The provided token isn't valid
Forbidden
The bot can't access this
TypeError
For a function that accepts ObjectWithIdAttribute
, the provided object doesn't have an id
attribute.