PiggyBank Discord Bot

Test this app for free
21
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()
Get full code

Frequently Asked Questions

How can the PiggyBank Discord bot help businesses manage their finances?

The PiggyBank Discord bot can be a valuable tool for businesses to track and manage their finances. It allows for creating multiple accounts, categorizing expenses with tags, and monitoring investments. This can help businesses keep a close eye on their cash flow, budget for different departments or projects, and make informed financial decisions. The bot's ability to generate reports and provide analytics can also assist in financial planning and forecasting.

Can the PiggyBank bot be used for personal finance management as well?

Absolutely! While the PiggyBank Discord bot can be used for business purposes, it's equally effective for personal finance management. Users can track their personal accounts, set budgets for different spending categories, manage subscriptions, and even create wishlists. The bot's features like expense tracking, investment monitoring, and financial reporting make it a comprehensive tool for individuals looking to improve their financial health and achieve their financial goals.

How does the PiggyBank bot handle multi-currency transactions?

The PiggyBank bot is designed to handle multi-currency transactions seamlessly. It uses an external API to fetch current exchange rates and can convert amounts between different currencies. This is particularly useful for businesses or individuals dealing with international transactions or managing accounts in multiple currencies. For example, when adding a new account or recording a transaction, users can specify the currency, and the bot will handle the conversions when generating reports or calculating net worth.

Can you explain how the PiggyBank bot implements the command for creating a new account?

Certainly! The PiggyBank bot implements the new account command using Discord's slash command feature. Here's a simplified version of the code:

```python @tree.command(name='new_account') async def new_account_command(interaction, account_name: str, amount: float = 0.0): currencies = fetch_currencies() select = Select(placeholder="Select a currency...", options=currencies)

   async def select_callback(interaction):
       user_id = interaction.user.id
       try:
           create_account(user_id, account_name, amount, select.values[0])
           await interaction.response.send_message(f"New account '{account_name}' created with {amount} {select.values[0]}")
       except IntegrityError:
           await interaction.response.send_message(f"Account '{account_name}' already exists")

   select.callback = select_callback
   view = View()
   view.add_item(select)
   await interaction.response.send_message("Choose a currency for your account", view=view)

```

This code defines a slash command that prompts the user for an account name and initial amount, then allows them to select a currency from a dropdown menu before creating the account.

How does the PiggyBank bot handle scheduled tasks like sending weekly reports?

The PiggyBank bot uses the APScheduler library to handle scheduled tasks. Here's an example of how it schedules the weekly report:

```python from apscheduler.schedulers.asyncio import AsyncIOScheduler

scheduler = AsyncIOScheduler()

async def send_weekly_report(): # Code to generate and send the report

def schedule_reports(): scheduler.add_job(send_weekly_report, 'cron', day_of_week='sun', hour=12, minute=0) scheduler.start()

# This function is called when the bot starts def main(): schedule_reports() bot.run(bot_token) ```

This code sets up a scheduler that runs the send_weekly_report function every Sunday at 12:00 PM. The scheduler is started when the bot initializes, ensuring that reports are sent automatically at the specified time.

Created: | Last Updated:

This app is a Discord bot that allows users to track various aspects of their finances such as accounts, spending types, wishlist items, transactions, investments, and many more!

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:

  1. 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:

  1. Go to the Discord Developer Portal (https://discord.com/developers/applications).
  2. Click "New Application" and give your application a name.
  3. Navigate to the "Bot" section in the left sidebar.
  4. Click "Add Bot" to create a bot user for your application.
  5. Under the "TOKEN" section, click "Reset Token" to generate a new token. Confirm by clicking "Yes, do it!"
  6. Copy the generated token.
  7. In the Lazy Builder, go to the "Environment Secrets" tab.
  8. 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:

  1. Go to https://www.exchangerate-api.com/
  2. Sign up for a free account.
  3. Once logged in, copy your API key from the dashboard.
  4. 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:

  1. 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:

  1. Go back to the Discord Developer Portal and select your application.
  2. Navigate to the "OAuth2" section in the left sidebar.
  3. In the "Scopes" section, select "bot".
  4. In the "Bot Permissions" section, select the permissions your bot needs (at minimum: Read Messages/View Channels, Send Messages, Use Slash Commands).
  5. Copy the generated OAuth2 URL.
  6. 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.



Template Benefits

  1. Personal Finance Management: This Discord bot provides a comprehensive platform for users to track and manage their personal finances, including accounts, transactions, investments, and budgets, all within the familiar Discord interface.

  2. Financial Education and Awareness: By offering features like budget tracking, investment monitoring, and spending analysis, the bot helps users become more aware of their financial habits and learn better money management skills.

  3. Community Engagement: As a Discord bot, this tool can be integrated into financial communities or servers, fostering discussions about personal finance and encouraging users to share tips and strategies.

  4. Customizable Financial Tracking: The bot allows users to create custom tags for transactions, set up personalized budgets, and manage multiple accounts and currencies, catering to diverse financial situations and goals.

  5. Data-Driven Insights: With features like spending reports, investment statistics, and budget analysis, the bot provides valuable insights that can help users make informed financial decisions and improve their overall financial health.

Technologies

Discord Automation & Bots Discord Automation & Bots

Similar templates

We found some blogs you might like...