Z
Z
Zakhar2020-08-06 17:30:40
Python
Zakhar, 2020-08-06 17:30:40

Add the server ID and default prefix to the database - discord.py rewrite, PostgreSQL?

And an owl good day to all <з !!!
There is such a code, when the bot enters the server, the server ID and the default prefix should be entered in the database.

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

PREFIX=str('.')


class prefix(commands.Cog):
    def __init__(self,bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_guild_join(self, guild):
        guildid= str(guild.id)
        await self.bot.execute(f'INSERN INTO prefixDB (guild_id, prefix) VALUES ({guildid},{PREFIX})')

    @commands.Cog.listener()
    async def on_guild_remove(self):
        pass

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

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


But it's not the task that gives the following error:
5f2c12f97b7e4067897732.png

On Heroku, here:
5f2c132d146c5032261352.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-08-06
@xzartsust

await self.bot.execute(f'INSERN INTO prefixDB (guild_id, prefix) VALUES ({guildid},{PREFIX})')

1) the request is wrong - replace INSERN with INSERT
2) try replacing bot with cursor

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question