Python 无法解决sqlite中计数器的问题
这样做的目的是,如果我向数据库中添加一个单词,那么每次键入相应单词时,它的计数应该是+1 我可以把这个词添加到数据库中,但是计数系统不工作Python 无法解决sqlite中计数器的问题,python,database,sqlite,discord.py,discord.py-rewrite,Python,Database,Sqlite,Discord.py,Discord.py Rewrite,这样做的目的是,如果我向数据库中添加一个单词,那么每次键入相应单词时,它的计数应该是+1 我可以把这个词添加到数据库中,但是计数系统不工作 @commands.command() async def wordadd(self, ctx, *args: str): message = " ".join(args).lower() word = db.column("SELECT word FROM words")
@commands.command()
async def wordadd(self, ctx, *args: str):
message = " ".join(args).lower()
word = db.column("SELECT word FROM words")
if message not in word:
db.execute("INSERT OR IGNORE INTO words (word) VALUES (?)",message)
db.commit()
await ctx.send("word has been added")
else:
await ctx.send("word already in there")
async def on_message(self, message):
word = db.column("SELECT word FROM words")
if message in word:
db.execute("UPDATE words SET count = count + 1 WHERE word = ?", message)
db.commit()
如何修复计数系统?试试这个
进口不和
导入sqlite3
从discord.ext导入命令
客户端=命令。Botcommand_前缀='。'
@客户端事件
_就绪时的异步定义:
打印就绪
异步def get_消息:
c、 executeSELECT*从消息中选择
返回c.fetchall
异步定义添加消息消息:
康涅狄格州:
c、 executeUPDATE消息集消息=:消息,
{'messages':message}
异步def remove_消息消息:
康涅狄格州:
c、 ExecuteElete消息=:来自消息的消息,
{'message':message}
异步定义添加用户消息用户id,消息:
康涅狄格州:
c、 executeUPDATE消息集消息=:消息+消息,其中user\u id=:user\u id,
{'message':消息'user\u id':user\u id}
@client.command
异步def add_messagectx,*,消息:str:
check=get\u消息
如果检查:
等待ctx.send该单词已在数据库中!
回来
其他:
msg=message.lower
等待添加消息msg
wait ctx.send成功添加{}.formatmessage
回来
@客户端事件
_message上的异步定义消息:
检查=等待获取消息
如果选中message.content.lower:
等待添加用户消息message.author.id,1
其他:
通过
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
client.runtoken
message=.joinargs.lower可能没有执行您希望它执行的操作。您可以使用print.jointest.lower来测试它,它将打印t