No project description provided
Project description
Disclaimer
Use this library responsibly and be sure to read Discord's Terms of Service before using.
Quickstart
Use the package manager pip to install.
pip install discbase
Set up a Discord bot
- Navigate to the Discord Developer Applications page
- Create a new application and name it
- Navigate to
Settings/General Information
and save theApplication ID
- Navigate to
Settings/Bot
- Click
Reset Token
, and save theToken
- Enable
Presence Intent
,Server Members Intent
, andMessage Content Intent
- Click
- Paste the application ID you saved into the following URL and paste it into any browser
- Select the server you would like to add this to and follow the prompts to authorize
Pick a Channel to Use for Storage
- Go to the server that you want to use. The bot you created should be there
- Find or create the channel you would like to use for storage, right click on the name and copy the channel ID
Run the Client
import asyncio
from discbase.database.Client import Client
if __name__ == "__main__":
# put your token here as a string
TOKEN = "TOKEN_123"
# put your channel id here as an integer
CHANNEL_ID = 123
client = Client(discord_client_token=TOKEN, discord_channel_id=CHANNEL_ID)
async def main():
# start the client
await client.start()
try:
# store some text data and some media
stored_record = await client.dump(value="some message", media_path="https://some_image.png")
# retrieve the data
retrieved_record = await client.retrieve(record_id=stored_record.record_id)
my_message = stored_record.text_data
my_media_url = stored_record.media_urls[0]
except Exception as e:
print(e)
# stop the client
await client.stop()
# run code asynchronously
asyncio.run(main())
Alternatively, Run the Client as a Context Manager
This is much slower as each time the context manager is used, it has to start up the client and connect first.
The advantage is closing will always be taken care of automatically.
import asyncio
from discbase.database.Client import Client
if __name__ == "__main__":
async def main():
# this runs the client
async with Client(discord_client_token="TOKEN_123", discord_channel_id=123) as client:
await client.dump(value="foo")
# the client is now closed automatically
asyncio.run(main())
Development
Run these commands from the root folder
- Install Dependencies:
make deps
- Format Code:
make fmt
- Run Unit Tests:
make test-unit
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
discbase-0.0.1.tar.gz
(11.1 kB
view hashes)
Built Distribution
discbase-0.0.1-py3-none-any.whl
(14.3 kB
view hashes)