我试图让一位被邀请的经理,我不断发现这一错误。
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)上移至一个称为变量的变量,但至今没有工作。
任何类型的建议或帮助都是有益的。