Reputation: 97
I am trying to insert some discord bot data to a database. I did the Parameters Method but it doesn't work. I am new to dealing with MYSQL with python.
My Code
@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()
My error
ValueError: 'params' arg (<class 'list'>) can be only a tuple or a dictionary.
Upvotes: 1
Views: 5045
Reputation: 6915
Apparently, the error message suggests you to use a tuple
instead of a list
in your cursor.execute
call. Besides that, your sql
query is not properly formed (see examples section). Your execute
call should rather look like this:
sql = "INSERT INTO Editedmsg VALUES (%d, %d, %d, %s, %s)"
params = (before.id, before.author.id, before.author.id,
before.content, after.content)
cursor.execute(sql, params)
Upvotes: 1