[英]can't figure out the issue with counter in sqlite
So what this does is, if I add a word to the db, it's supposed to +1 to the count for the respective word every time it's typed所以这样做的作用是,如果我向数据库中添加一个单词,它应该在每次输入时为相应单词的计数增加 1
I can add the word to the db, but the counting system isn't working我可以将单词添加到数据库中,但计数系统不起作用
@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()
how can I fix the counting system?如何修复计数系统?
Try this尝试这个
import discord
import sqlite3
from discord.ext import commands
client = commands.Bot(command_prefix='.')
@client.event
async def on_ready():
print("Ready")
async def get_messages():
c.execute("SELECT * FROM messages")
return c.fetchall()
async def add_message(message):
with conn:
c.execute("UPDATE message SET messages=:message",
{'messages': message})
async def remove_message(message):
with conn:
c.execute("DELETE message=:message FROM message",
{'message': message})
async def add_user_message(user_id, message):
with conn:
c.execute("UPDATE message SET messages=:message + messages WHERE user_id=:user_id",
{'message': message, 'user_id': user_id})
@client.command()
async def add_message(ctx, *, message: str):
check = get_messages()
if check:
await ctx.send("That word is already on the database!")
return
else:
msg = message.lower()
await add_message(msg)
await ctx.send("Succesfully added {}".format(message))
return
@client.event
async def on_message(message):
check = await get_messages()
if message.content.lower() in check:
await add_user_message(message.author.id, 1)
else:
pass
if __name__ == '__main__':
client.run("token")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.