python-3.x - 如何制作在页脚中显示时间戳的狙击命令
问题描述
我可以使用 'pytz' 库和 'datetime' 库获取 UTC 时间,但我需要用户本地时间。假设你从美国运行狙击命令,你应该得到你的当地时间,如果我从意大利运行它,我应该得到意大利的时间。我希望我说清楚了。
x = message = {}
y = author = {}
z = author_avatar = {}
time = {}
@client.event
async def on_message_delete(msg):
UTC = pytz.utc
datetime_utc = datetime.now(UTC)
if msg.author.bot == False:
x[msg.channel.id] = msg.content
y[msg.channel.id] = msg.author
time[msg.channel.id] = datetime_utc.strftime('%H:%M UTC')
if msg.author == client.user:
x[msg.channel.id] = msg.content
y[msg.channel.id] = msg.author
time[msg.channel.id] = datetime_utc.strftime('%H:%M UTC')
@client.command(name = 'snipe')
async def snipe(ctx):
try:
em = discord.Embed(description = f" {x[ctx.channel.id]}" ,color = random.choice(colors_for_embeds1), timestamp = datetime.now())
em.set_author(name = y[ctx.channel.id] ,icon_url = (y[ctx.channel.id]).author.url)
em.set_footer(text = f"at {time[ctx.channel.id]}")
await ctx.send(embed = em)
except:
await ctx.send("There is nothing to snipe!")
这就是命令的工作方式。删除的消息以频道 ID 作为键添加到字典中,作者 ID 以频道 ID 保存在字典中。
解决方案
我希望这回答了你的问题。
您所在位置的 UTC 时间更新,因此对您而言,它将显示您的时间(例如:今天上午 8:00),然后为世界其他地方的其他人显示时间(今天上午 9:00)。
我不知道我是否回答得好,或者你是否理解。但希望能回答你的问题!:D
推荐阅读
- python - 带有时间索引的 Pandas 数据帧和带有乘数的频率
- reactjs - 地图未在 React-Left 304 http 中加载
- powershell - Powershell foreach 帮助。有人可以帮忙让它只循环一次吗?
- java - 菜单图标未显示在工具栏中
- flutter - firebase登录后如何自动重定向?
- sql - 使用窗口函数引用前一行值
- java - 为什么我的 androidx.test 导入在调试构建变体中不起作用?
- swift - 网络调用语法 Xcode 的编译器错误
- jmeter - 通过 CLI 运行 Jmeter 脚本时出错
- python - 如何获取 ManyToMany 字段中的值的计数