【发布时间】:2020-11-27 22:29:24
【问题描述】:
我创建了一个自定义命令,更像是自定义标签命令,但我想检查一下,如果有相同的标签名称,发送一条消息,表明该名称的标签已经存在 我尝试使用此代码,但它不断将新标签记录到 sqlite 虽然它已经存在。
@tags.command()
async def create(self, ctx, tag=None, *,text=None):
db = sqlite3.connect('main.db')
cursor = db.cursor()
cursor.execute(f"SELECT text FROM tags WHERE guild_id = {ctx.guild.id} and tag")
result = cursor.fetchone()
if result is None:
sql = (f"INSERT INTO tags(guild_id, tag, text) VALUES(?,?,?)")
val = (ctx.guild.id, tag, text)
await ctx.send(f'Created {tag}!')
cursor.execute(sql, val)
db.commit()
if result is not None:
await ctx.send(f'Tag named {tag} was already exist.')
cursor.close()
db.close()
【问题讨论】:
标签: sqlite discord discord.py discord.py-rewrite