Skip to main content

A simple database which uses a Discord channel to store data.

Project description

DiscordDBPlus

Documentation Status

A simple database which uses a Discord channel to store data. This is a fork from thec0sm0s's DiscordDB. This version aims to be more flexible.

Features

  • Sending multiple data packs at the same time
  • Edit a data entry from a message id.
  • searches data fields into multiple channels and multiple messages

Installation

To install current latest release you can use following command:

python3 -m pip install DiscordDBPlus

Basic Example

from discordDBPlus import DiscordDB
from discord.ext import commands


LOGS = []


class MyBot(commands.Bot):

    def __init__(self):
        super().__init__(command_prefix="!")
        self.discordDB = DiscordDB(self) # You need to give the bot object to the DiscordDB instance

    @commands.command()
    async def log(self, ctx, *, text):
        data = {
            "name": ctx.author.name,
            "text": text
        }
        _id = await self.discordDB.save(data, id of a channel:int)
        LOGS.append(_id)

    @commands.command()
    async def show_logs(self, ctx):
        for _id in LOGS:
            data = await self.discordDB.get(_id, id of a channel:int)
            await ctx.send(f"Name: {data.name}, Text: {data.text}")

    @commands.command()
    async def edit_data(self, ctx, id):
        _id = int(id)
        data = await DB.get(_id, id of a channel:int)
        data.name = "example modification"
        data.textEdited = "Edited text"
        await DB.edit(data, _id, id of a channel:int)

    @commands.command()
    async def get_one_field(self, ctx):
        for _id in LOGS:
          data = await self.discordDB.getf(_id, "A field", id of a channel:int)
          await ctx.send(f"Text: {data.content}")


bot = MyBot()
bot.run("TOKEN")

If you wish to save the LOGS to be able to recover them after the bot closed, you can consider put it in a file using json or some file managment system.

Since the 0.0.8 version, the initial declaration of the instance of DiscordDB don't take a channel id argument anymore. Instead, to have more flexibility, you need to give the channel id inside the arguments of the command you want to use.

Requirements

  • discord.py

Documentation

Head over to documentation for full API reference.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

DiscordDBPlus-0.0.9.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

DiscordDBPlus-0.0.9-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file DiscordDBPlus-0.0.9.tar.gz.

File metadata

  • Download URL: DiscordDBPlus-0.0.9.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.5

File hashes

Hashes for DiscordDBPlus-0.0.9.tar.gz
Algorithm Hash digest
SHA256 943d3da47bcf058a1c5e111647bb221686a4856aa3e38b1b6292519c9ac3d1bd
MD5 b4e05c8c402e350f4e454b0bd2040572
BLAKE2b-256 ad684b556bae14c4347ec94b1a1c4905918b4d3d43ab3c64c017bdc58745686a

See more details on using hashes here.

Provenance

File details

Details for the file DiscordDBPlus-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: DiscordDBPlus-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.5

File hashes

Hashes for DiscordDBPlus-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 35aa6eb6055741a6ac111c3ab14b93d2d28c0d4db55b61f11e8bdf43f65909f4
MD5 a042615f9c04f461b7e08b88502904a6
BLAKE2b-256 d23e055106691536bc9727181de6dd8b813fd983aa9d5db90d516fc434cb7e23

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page