[英]How can I get the timestamp of a message in Discord.py?
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.我知道这是错误的,因为 discord.Message 给出了一个对象。 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.目前您正在调用
discord.Message
类,但实际上您想调用从该方法中获得的消息对象。 So just use message
instead of discord.Message
.所以只需使用
message
而不是discord.Message
。
Note: message.created_at
actually already returns a datetime object.注意:
message.created_at
实际上已经返回了一个日期时间对象。 documentation 文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.