0

我遇到了一个问题,即我的不和谐机器人在流量负载后停止回复使用数据库(postgresql 和 asyncpg)的命令。

我检查了数据库,它没有离线或任何东西,我也没有收到任何错误。

help工作正常,因为它不使用数据库

我如何创建/使用连接:

#How I create the connection

async def create_connection_pool():
    bot.pg_conn = await asyncpg.create_pool(**credentials)
@bot.event
async def on_ready():
    await create_connection_pool()

#How I use it

@voice.command()
    async def name(self, ctx,*, name):
        con = await self.bot.pg_conn.acquire()
        id = ctx.author.id
        voice = await self.bot.pg_conn.fetchrow("SELECT * FROM voice_channels WHERE user_id = $1", id)
        if voice is None:
            await ctx.channel.send(f"{ctx.author.mention} You don't own a channel.")
        else:
            channel = self.bot.get_channel(voice['voice_channel_id'])
            await channel.edit(name = name)
            await ctx.channel.send(f'{ctx.author.mention} You have changed the channel name to '+ '{}!'.format(name))
            voice = await self.bot.pg_conn.fetchrow("SELECT * FROM user_settings WHERE user_id = $1", id)
            if voice is None:
                async with con.transaction():
                    await con.execute("INSERT INTO user_settings VALUES ($1, $2, $3)", (id,name,0))
            else:
                async with con.transaction():
                    await con.execute("UPDATE user_settings SET channel_name = $1 WHERE user_id = $2", name, id)
        await self.bot.pg_conn.release(con)

关于我可能做错了什么的任何想法?

我试过使用 try/except 没有得到任何东西

在那里添加了一堆调试打印,没有过去

15 | voice = await self.bot.pg\_conn.fetchrow("SELECT \* FROM voice\_channels WHERE user\_id = $1", id)

并尝试为 fetch 添加超时,但没有做任何事情。虽然当我做键盘中断时,它在关闭并运行打印之前从获取中出来。

如果有人可以帮助我,我将不胜感激。

4

0 回答 0