【问题标题】:Timestamp For Discord Bot StatusDiscord Bot 状态的时间戳
【发布时间】:2021-10-29 17:46:25
【问题描述】:

我正在使用 Discord.js Node V12 我目前正在尝试找出如何在状态中表示经过的时间,以显示机器人玩游戏或任何活动的时间。但我找不到任何提出或回答过这些问题的人。

@client.event
async def on_connect():
  await client.change_presence(status=discord.Status.dnd,activity = discord.Game(name = "VALORANT"))

【问题讨论】:

  • 这看起来像 python,而不是 javascript。
  • 您使用了 discord.py 标签,并且您在问题中有 discord.py 代码,并且您说您使用的是 discord.js node v12?
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: node.js discord.js bots


【解决方案1】:

我想把这个答案分成几个重要的点:

• 提供的示例代码来自 discord.py(一个已停产的基于 python 的与 API 交互的库),它完全脱离了整个问题本身的上下文,因为您要求它提供 discord.js

• 到目前为止,还没有实际的方法可以找到自特定活动以来经过的时间,但您可以诉诸于此:

var uptime = client.uptime; // returns uptime in milliseconds
var hours = uptime / 1000 / 60 / 60 // converts it to hours 
/* 
Then you may apply the following approach to change your status every hour passes 
*/
setInterval(() => {
    client.user.setActivity(`Valorant since ${hours} hour(s)`);
  }, 3600000); // this would show up as Playing Valorant since 1 hour(s) and subsequently would change every hour if your bot isn't being restarted continuously.

【讨论】:

  • OP 用 python 写了他的问题,而不是 Javascript。 setInterval 对于 OP 试图实现的目标也非常低效。也许尝试计算毫秒值(或 1 小时内的时间),然后定期检查是否是那个时间。
  • 我同意乔的观点,他们用 python 编写了他们的代码,但是它显然有一个 discord.js 标记,他们提到他们正在使用 nodejs V12 和 discord.js,另外我同意 @987654323 @ 这不是一个非常有效的方法,我建议 node-cron 用于预定状态更改:)
【解决方案2】:

我查看了discord.js documentation to examine setting activities 并没有发现有关时间戳的此类信息。但是,ActivityType 中有一个部分将我带到了discord developers documentation,它表明:

机器人只能发送nametype 和可选的url

因此,您似乎无法将活动设置为机器人的开始或结束时间戳。

【讨论】:

    猜你喜欢
    • 2021-06-29
    • 2021-04-24
    • 1970-01-01
    • 2019-08-01
    • 2023-03-05
    • 2022-07-21
    • 2021-07-28
    • 2021-07-30
    • 1970-01-01
    相关资源
    最近更新 更多