So I have been trying to do a bot, that gets when the message was sent and upload it to a database. I just can't figure this Object thing out.
Here is some of my code:
'{datetime.datetime.fromtimestamp(discord.Message.created_at)}'
I know this is wrong, because the discord.Message gives an object. How can I get an integer or a time out of it?
EDIT:
@client.command()
async def belep(message, url, felhasz, jelsz):
if isinstance(message.channel, discord.DMChannel):
for i in c:
if i['Url'] == url:
db = MySQLdb.connect(xxxxx)
cursor = db.cursor()
print(url + " " + felhasz + " " + jelsz)
icode = i["InstituteCode"]
headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'}
payload = {'institute_code': f'{icode}', 'userName': f'{felhasz}', 'password': f'{jelsz}',
'grant_type': 'password', 'client_id': '919e0c1c-76a2-4646-a2fb-7085bbbf3c56'}
response = requests.get(f"""https://{icode}.e-kreta.hu/idp/api/v1/Token""", headers=headers, data=payload)
rjson = response.json()
print()
cursor.execute(
f"INSERT INTO token (mauthor, access_token, token_type, expires_in, refresh_token, msent, tokexpire) VALUES ('{message.author.id}', '{rjson['access_token']}', '{rjson['token_type']}', '{rjson['expires_in']}', '{rjson['refresh_token']}', '{datetime.datetime.fromtimestamp(discord.Message.created_at)}','{datetime.datetime.fromtimestamp(discord.Message.created_at)}')")
At the moment you are calling the discord.Message
class, but you actually wanna call the message object you get from the method. So just use message
instead of discord.Message
.
Note: message.created_at
actually already returns a datetime object. documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With