English 中文(简体)
类型:共同物体不支持按年龄划分的环境主管程序
原标题:TypeError: coroutine object does not support the asynchronous context manager protocol

我试图让一位被邀请的经理,我不断发现这一错误。

  async with cursor.execute("SELECT id, uses FROM invites WHERE guild_id = ?", (member.guild.id,)) as cursor:
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Ignoring exception in on_member_join
Traceback (most recent call last):
  File "C:UsersachaAppDataLocalProgramsPythonPython311Libsite-packagesdiscordclient.py", line 378, in _run_event
    await coro(*args, **kwargs)
  File "D:ProjectsSkriptsNet-Botmodulesinvites.py", line 48, in on_member_join
    async with cursor.execute("SELECT id, uses FROM invites WHERE guild_id = ?", (member.guild.id,)) as cursor:
TypeError:  coroutine  object does not support the asynchronous context manager protocol

这是我目前正在使用的法典:

    # Member Join Event
        
    @commands.Cog.listener()
    async def on_member_join(self, member):
        async with aiosqlite.connect(self.DB) as db:
            async with db.cursor() as cursor:
                invites = await member.guild.invites()

                c = datetime.today().strftime("%Y-%m-%d").split("-")
                c_y = int(c[0])
                c_m = int(c[1])
                c_d = int(c[2])

                async with cursor.execute("SELECT id, uses FROM invites WHERE guild_id = ?", (member.guild.id)) as cursor:
                    async for invite_id, old_uses in cursor:
                        for invite in invites:
                            if invite.id == invite_id and invite.uses - old_uses > 0:
                                if not (c_y == member.created_at.year and c_m == member.created_at.month and c_d - member.created_at.day < 7):
                                    print(invite.id)
                                    await cursor.execute("UPDATE invites SET uses = uses + 1 WHERE guild_id = ? AND id = ?", (invite.guild.id, invite.id))
                                    await cursor.execute("INSERT OR IGNORE INTO joined (guild_id, inviter_id, joiner_id) VALUES (?,?,?)", (invite.guild.id, invite.inviter.id, member.id))
                                    await cursor.execute("UPDATE totals SET normal = normal + 1 WHERE guild_id = ? AND inviter_id = ?", (invite.guild.id, invite.inviter.id))

                                else:
                                    await cursor.execute("UPDATE totals SET normal = normal + 1, fake = fake + 1 WHERE guild_id = ? and inviter_id = ?", (invite.guild.id, invite.inviter.id))

                                return
            await db.commit()

我试图将<代码>cursor.execute(“SlectT id”,从邀请WHERE guild_id = ?” (成员:guild.id)上移至一个称为变量的变量,但至今没有工作。

任何类型的建议或帮助都是有益的。

问题回答
# Member Join Event
@commands.Cog.listener()
async def on_member_join(self, member):
    db = await aiosqlite.connect(self.DB)
    try:
        cursor = await db.cursor()
        try:
            invites = await member.guild.invites()

            c = datetime.today().strftime("%Y-%m-%d").split("-")
            c_y = int(c[0])
            c_m = int(c[1])
            c_d = int(c[2])

            await cursor.execute("SELECT id, uses FROM invites WHERE guild_id = ?", (member.guild.id))
            async for invite_id, old_uses in cursor:
                for invite in invites:
                    if invite.id == invite_id and invite.uses - old_uses > 0:
                        if not (c_y == member.created_at.year and c_m == member.created_at.month and c_d - member.created_at.day < 7):
                            print(invite.id)
                            await cursor.execute("UPDATE invites SET uses = uses + 1 WHERE guild_id = ? AND id = ?", (invite.guild.id, invite.id))
                            await cursor.execute("INSERT OR IGNORE INTO joined (guild_id, inviter_id, joiner_id) VALUES (?,?,?)", (invite.guild.id, invite.inviter.id, member.id))
                            await cursor.execute("UPDATE totals SET normal = normal + 1 WHERE guild_id = ? AND inviter_id = ?", (invite.guild.id, invite.inviter.id))

                        else:
                            await cursor.execute("UPDATE totals SET normal = normal + 1, fake = fake + 1 WHERE guild_id = ? and inviter_id = ?", (invite.guild.id, invite.inviter.id))

                        return
        finally:
            await cursor.close()
    finally:
        await db.close()
    await db.commit()

问题似乎得不到支持,与我的情况类似,最后,我以最后的方式取代,这一法典将结束联系,不管发生什么事情(最后是RAII,总是可以执行),此外,你可以提出一种例外。





相关问题
sqlite3 is chopping/cutting/truncating my text columns

I have values being cut off and would like to display the full values. Sqlite3 -column -header locations.dbs " select n.namelist, f.state, t.state from names n left join locations l on l.id = n.id ...

Entity Framework with File-Based Database

I am in the process of developing a desktop application that needs a database. The application is currently targeted to SQL Express 2005 and works wonderfully. However, I m not crazy about having ...

Improve INSERT-per-second performance of SQLite

Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second! Background: We are using SQLite as part of a desktop ...

Metadata for columns in SQLite v2.8 (PHP5)

How can I get metadata / constraints (primary key and "null allowed" in particular) for each column in a SQLite v2.8 table using PHP5 (like mysql_fetch_field for MySql)? sqlite_fetch_column_types (OO:...

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签