Databases

Video Tutorial

This video tutorial goes over how to save data using databases in inventor.


https://www.youtube.com/watch?v=Tj7DJtbMurI

Written Tutorial

Database Management Tutorial

This tutorial will guide you through creating a database, looking up user points, and updating points in the database using flows. Follow these steps to build and test your setup.


Step 1 - Create a New Database

On your dashboard sidebar, find and click on the Database tab.

In the top-right corner, click the New Database button.

Name the database points and click Create Database.

Step 2 - Add Columns

You'll be redirected to the database editor. Here, add the following columns:

  • user_id
  • points

Your database is now ready.


Step 3 - Looking Up Values in the Database

Create a Flow

  • Create a new flow and name it Lookup User Points.
  • Set the trigger to Slash Command.
  • Name the command lookup-points.

Step 4 - Add a Lookup by Value or Create Block

Add a Lookup by Value or Create block and configure it as follows:

  • Select the points database from the dropdown.
  • Select the user_id collumn from the dropdown.
  • Set the Value field to the user ID of the executing user.

Step 5 - Add a Text Reply to Interaction Block

  • Add this block and write the message:
    • The user has {points} points.
  • Use the points variable from the Lookup block to display the {points} value.

Step 6 - Test the Command

  • Run /lookup-points in Discord. The bot should respond with:
    • The user has points.

If no points are saved yet, the response may show a blank value. Don't worry, this will be updated in the next step.


Step 7 - Editing the Database with a Flow

Create a Flow

  • Create a new flow and name it Add Points to User.
  • Set the trigger to Slash Command.
  • Name the command add-point.

Step 8 - Add a Lookup by Value or Create Block

Add a Lookup by Value or Create block to the flow and configure it as follows:

  • Select the points database from the dropdown.

  • Select the user_id collumn from the dropdown.

  • Set the Value field to the user ID of the executing user.


Step 9 - Add a Math Operations Block

Add a Math Operations block and configure it to increment the points:

  • Value 1: Use the points value from the Lookup block.
  • Operation: Addition.
  • Value 2: Set this to 1.

Step 10 - Add an Update Row Block

Add a Update Row block and configure it as follows:

  • Select the points database.
  • Row ID: Use the row ID from the Lookup block.
  • Keep Value if Blank: Turn this option on.
  • Set the points field to the result of the Math Operations block.

Step 11 - Add a Text Reply to Interaction Block

Write a response to the user like "Added one point".

Test the Command

Run /add-point in Discord. The bot should add a point in the database, and respond with your message.

Use /lookup-points to verify the update. The bot should now respond with the user's new points total.


Now your bot can track and update points for users with simple commands! Use this setup to build more features that interact with your database.