libcurrency is a Python library created to be an easy currency implementation for Discord bots.
Designed for HiggsBot.
import libcurrency
import asyncio
import discord
currency = libcurrency.Token()
@bot.event
async def on_ready():
await currency.start() # Needs to be ran once at the start of the bot. This is the function that gives currency over time.
bot.loop.create_task(currency.payment()) # Starts the loop that awards users CodeTokens.
@bot.listen()
async def on_member_join(member):
currency.join(member)
currency.check_balance(user) # Returns the amount of codetokens belonging to a user.
try:
currency.remove_tokens(user, amount) # Removes codetokens from a user
except Exception as e:
print(e)
currency.set_balance(user, amount) # Set codetoken balance to a specific value for a user
See test.py for further usage example.
See the Testing branch for an implementation example.
The library relies on Async IO to be able to run the codetoken awarding function in the background.
Since Discord.py requires this as well, it doesn't add unnecessary bulk to the code.
Dataset is used to store user data.