Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Discord.py中获取消息的时间戳?_Python_Datetime_Object_Discord_Discord.py - Fatal编程技术网

Python 如何在Discord.py中获取消息的时间戳?

Python 如何在Discord.py中获取消息的时间戳?,python,datetime,object,discord,discord.py,Python,Datetime,Object,Discord,Discord.py,所以我一直在尝试做一个机器人,当消息被发送并上传到一个数据库时,它会被获取。我就是搞不懂这个东西 以下是我的一些代码: '{datetime.datetime.fromtimestamp(discord.Message.created_at)}' 我知道这是错误的,因为不和谐。信息给出了一个对象。如何从中获取整数或时间 编辑: 此时,您正在调用discord.Message类,但实际上您希望调用从该方法获得的消息对象。所以只需使用message而不是discord.message 注意:mes

所以我一直在尝试做一个机器人,当消息被发送并上传到一个数据库时,它会被获取。我就是搞不懂这个东西

以下是我的一些代码:

'{datetime.datetime.fromtimestamp(discord.Message.created_at)}'
我知道这是错误的,因为不和谐。信息给出了一个对象。如何从中获取整数或时间

编辑:


此时,您正在调用
discord.Message
类,但实际上您希望调用从该方法获得的消息对象。所以只需使用
message
而不是
discord.message


注意:
message.created\u at
实际上已经返回了一个datetime对象

显示你的全部代码,否则我们不知道你从哪里得到消息。我已经编辑过了。
@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)}')")