PiggyBank Discord Bot
import io
import aioschedule
from crud import delete_wishlist_item, edit_subscription, delete_subscription, create_subscription, view_recurring_subscriptions, view_non_recurring_subscriptions, set_account_amount, get_wishlist, update_wishlist_item, set_investment_value, delete_investment, get_investments_for_user, update_tag, get_transactions_for_user, create_investment, create_wishlist_item, create_transaction, get_user, get_all_tags, create_account, get_account, get_all_accounts, delete_account, update_account_amount, create_tag, delete_tag, get_budget, update_budget
from fetch_currencies import fetch_currencies, convert_currency
from analytics import all_in_one_analysis, get_investment_statistics, generate_spending_report
from flask import Flask
from app_init import app, tree, bot, bot_token
import discord
from discord import app_commands, Interaction
from sqlalchemy.exc import IntegrityError
import os
from discord.ui import Select, View
import asyncio
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from database import db
from accounts import *
from stats import *
from tags import *
from investments import *
from subscriptions import *
from wishlist import *
from budgets import *
scheduler = AsyncIOScheduler()
Created: | Last Updated:
Here's a step-by-step guide for using the PiggyBank Discord Bot template:
Introduction
The PiggyBank Discord Bot is a powerful financial tracking tool that integrates with Discord. It allows users to manage various aspects of their finances, including accounts, spending categories, wishlist items, transactions, investments, and more. This bot can help Discord users keep track of their financial health directly within their Discord server.
Getting Started
To begin using this template:
- Click the "Start with this Template" button in the Lazy Builder interface.
Initial Setup
Before testing the bot, you need to set up a Discord bot and obtain its token. Follow these steps:
- Go to the Discord Developer Portal (https://discord.com/developers/applications).
- Click "New Application" and give your application a name.
- Navigate to the "Bot" section in the left sidebar.
- Click "Add Bot" to create a bot user for your application.
- Under the "TOKEN" section, click "Reset Token" to generate a new token. Confirm by clicking "Yes, do it!"
- Copy the generated token.
- In the Lazy Builder, go to the "Environment Secrets" tab.
- Add a new secret with the key
DISCORD_BOT_TOKEN
and paste your bot token as the value.
Additionally, you need to set up an API key for currency conversion:
- Go to https://www.exchangerate-api.com/
- Sign up for a free account.
- Once logged in, copy your API key from the dashboard.
- In the Lazy Builder's "Environment Secrets" tab, add another secret with the key
EXCHANGE_RATE_API_KEY
and paste your API key as the value.
Testing the Bot
After setting up the environment secrets:
- Click the "Test" button in the Lazy Builder interface to start the deployment process.
Using the Bot
Once the bot is deployed, you can invite it to your Discord server:
- Go back to the Discord Developer Portal and select your application.
- Navigate to the "OAuth2" section in the left sidebar.
- In the "Scopes" section, select "bot".
- In the "Bot Permissions" section, select the permissions your bot needs (at minimum: Read Messages/View Channels, Send Messages, Use Slash Commands).
- Copy the generated OAuth2 URL.
- Open this URL in a new browser tab and select the Discord server where you want to add the bot.
After adding the bot to your server, you can start using its commands. Here are some example commands:
/new_account
: Create a new financial account/spent
: Record an expense/money_in
: Record income/view_transactions
: View your transaction history/new_tag
: Create a new spending category/new_investment
: Add a new investment/new_subscription
: Add a recurring subscription/view_wishlist
: View your wishlist items/net_worth
: Calculate your net worth
Each command will guide you through the process of entering the required information.
Integrating the Bot
This Discord bot is designed to work within Discord servers. There's no additional integration required beyond adding it to your desired Discord server and using its commands.
Remember to keep your bot token and API keys secure. Never share them publicly or commit them to version control systems.