【问题标题】:How do I get the timezone of the message author in my discord server? (discord.py)如何在我的不和谐服务器中获取消息作者的时区? (discord.py)
【发布时间】:2020-03-26 21:03:44
【问题描述】:

如何添加根据人员时区发送消息时显示的页脚?

Image Example

例如

import discord
import datetime

client = discord.Client()

@client.event
async def on_ready():
    await client.change_presence(activity=discord.Game('Exodus Hub | !cmds'))
    print('Logged in as {0.user}'.format(client))


@client.event
async def on_message(msg):
    print(msg.created_at)
    print(msg.author)
    if msg.author == client.user:
        return
    if msg.content.lower() == '!getscript':
        if str(msg.channel) == 'bot-cmds':
            if 'Developers' in str(msg.author.roles):
                richembed = discord.Embed(title='Exodus Server Bot',colour=0xff0000, description='Sending....')
                date = datetime.datetime.now()
                richembed.set_footer(text=f'{date:%b} at {date:%H:%M}') #<--- Footer
                await msg.channel.send(content=None,embed=richembed)

client.run('redacted')

【问题讨论】:

    标签: python python-3.x discord.py


    【解决方案1】:

    Discord 嵌入有一个 timestamp 字段,可以设置为 datetime 对象。遗憾的是,无法通过 Discord 提供的 API 确定用户的时区。

    discord.py 的嵌入数据类可以查看documentation。

    【讨论】:

      【解决方案2】:

      嵌入中的timestamp 字段实际上会以用户的本地时间显示。但是,您也可以使用Timestamp Styles 将当地时间放在嵌入和/消息中的其他位置。它需要在 EPOCH 秒,而不是毫秒:

      // one hour from now
      <t:${Math.floor(new Date(new Date().getTime() + 60 * 60000).getTime() / 1000)}:t>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-01-20
        • 2020-12-14
        • 2020-09-25
        • 2020-08-22
        • 2022-01-04
        • 2021-02-12
        • 2020-09-09
        相关资源
        最近更新 更多