A simple database which uses a Discord channel to store data.
Project description
DiscordDBPlus
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.
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 = []
DATABASE_CHANNEL_ID = The id of a channel (int)
class MyBot(commands.Bot):
def __init__(self):
super().__init__(command_prefix="!")
self.discordDB = DiscordDB(self, DATABASE_CHANNEL_ID)
@commands.command()
async def log(self, ctx, *, text):
data = {
"name": ctx.author.name,
"text": text
}
_id = await self.discordDB.save(data)
LOGS.append(_id)
@commands.command()
async def show_logs(self, ctx):
for _id in LOGS:
data = await self.discordDB.get(_id)
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)
data["name"] = "example modification"
data["text3"] = "Edited text"
await DB.edit(data, _id)
@commands.command()
async def get_one_field(self, ctx):
for _id in LOGS:
data = await self.discordDB.getf(_id, "A field")
await ctx.send(f"Text: {data}")
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.
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.7.tar.gz
(4.3 kB
view hashes)
Built Distribution
Close
Hashes for DiscordDBPlus-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f509b0c5560259d4ce1b1b79c8e2fd484296b9ac2d87bbb7b64d35a76daf0d94 |
|
MD5 | a25675cc26c59c21806ef3bf94a02cdc |
|
BLAKE2b-256 | 044d4d119c325afa19f8ad14bf2aaa24fa4875e57ee6638d460605e838ad945f |