Z
Z
Zakhar2020-08-09 09:48:01
Python
Zakhar, 2020-08-09 09:48:01

How to connect a database to a discord bot, and how to use it (Host HEROKU) - discord.py PostgreSQL?

Hello!
I have this code:

import discord
from discord.ext import commands
import os
import asyncpg, asyncio

PREFIX=('.')

class prefix(commands.Cog):
    def __init__(self,bot):
        self.bot = bot
        
    @commands.Cog.listener()
    async def on_guild_join(self, guild):
        pass
        
    @commands.Cog.listener()
    async def on_guild_remove(self,ctx):
        pass

    @commands.command()
    @commands.has_permissions(administrator=True)
    async def prefix(self, ctx, prefix):
        pass

def setup(bot):
    bot.add_cog(prefix(bot))

url = os.environ.get('db')

Instead of pass there will be functions

How to connect the database to this code so that it can be used in other bot files.

Another question is what kind of database should be used, there is a PostgreSQL addon on Heroku, or you need to install PostgreSQL itself. I have this and that but nothing comes out (

I would be very grateful !!!!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2020-08-09
@xzartsust

Have you even read the setup documentation?
5f2fbba8e1d54191027026.png
after these settings, install postgresql and pgAdmin (they are included, it will be unnecessary to climb different sites).
start the pgAdmin server, connect to the Heroku databases, search for your own among the list of strangers and work with it.

A
Andrey, 2020-08-09
@anerev

Library for working with postgres psycopg2. You need to create a database on your computer, and then transfer it to heroku

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question