我正在尝试向数据库中插入一些不一致的bot数据。我做了参数法,但它不工作。我对用python处理mysql还不熟悉。
我的代码
@bot.event
# Edit Log
async def on_message_edit(before, after):
MemberId = before.author.id
await bot.send_message(bot.get_channel('480526097331650590'), 'The user <@%s> have edited his message from ``' % (MemberId) + before.content + '`` to `` ' + after.content + ' `` ')
#Connection to sql
conn = pymssql.connect(server='HAMOOOOD25\DISCORDPY', user='sa', password='31045', database='ChatLogs')
cursor = conn.cursor()
#Declaring vars
BeforeId = before.id
BAuthId = before.author.id
BAuthN = before.author.id
Befcon = before.content
Aftcon = after.content
sql = "INSERT INTO Editedmsg VALUES (Message_ID, Message_Author_ID, Message_Owner_Name, Previous_Message, After_Message)"
cursor.execute(sql, [(before.id), (before.author.id,), (before.author.id), (before.content), (after.content)])
conn.close()
我的错误
ValueError: 'params' arg (<class 'list'>) can be only a tuple or a dictionary.
1条答案
按热度按时间z9ju0rcb1#
显然,错误消息建议您使用
tuple
而不是list
在你的cursor.execute
打电话。除此之外,你的sql
查询的格式不正确(请参阅示例部分)。你的execute
电话应该是这样的: