Reputation: 37
So I set up MySQL for my discord.py bot. I'm planning to do some small project to test myself on my friend server.
I want it to count how many messages are sent on a week, but it doesn't work. It gives me this error:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\Rui\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Rui\Desktop\Python\mudaenotifier\kyoreborn.py", line 40, in on_message
cursor.execute(query,[(username)])
File "C:\Users\Rui\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor_cext.py", line 257, in execute
prepared = self._cnx.prepare_for_mysql(params)
File "C:\Users\Rui\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\connection_cext.py", line 665, in prepare_for_mysql
result = self._cmysql.convert_to_mysql(*params)
_mysql_connector.MySQLInterfaceError: Python type Member cannot be converted
What can I do with this?
Here is my code:
@client.event
async def on_message(message):
username=message.author
print(username)
query="SELECT * FROM messages WHERE username=%s"
cursor.execute(query,[(username)])
results=cursor.fetchall()
if results:
query="UPDATE messages SET messagecount = messagecount + 1 WHERE username = %s"
cursor.execute(query,[(username)])
con.commit()
con.close()
else:
query = "INSERT INTO `messages`(username,messagecount) VALUES (%s,1)"
cursor.execute(query, [(username)])
con.commit()
con.close()
await client.process_commands(message)
Upvotes: 0
Views: 59
Reputation: 15689
message.author
returns a discord.Member
instance, use str(message.author)
instead to cast it to a string.
Upvotes: 2