【发布时间】:2022-07-18 10:15:34
【问题描述】:
当我使用 disnake 编写我的不和谐机器人时,当我使用 /status 时,正常运行时间不会显示所有需要的信息,而是:<function status.<locals>.uptimed at 0x000001C35A56FE20> 发生了什么,以及如何解决它?
代码:
@bot.slash_command(description="Mostra a latência do bot", pass_context=True)
async def status(self, interaction: disnake.CommandInteraction):
await interaction.response.defer()
def uptimed():
pass
current_time = time.time()
difference = int(round(current_time - start_time))
text = str(datetime.timedelta(seconds=difference))
text.replace(" years", "Y")
text.replace(" year", "Y")
text.replace(" months", "M")
text.replace(" month", "M")
text.replace(" days", "d")
text.replace(" day", "d")
print(uptimed)
before = time.monotonic()
carregando = disnake.Embed(
description="⏳ - Carregando...",
color=0x00ffff
)
await interaction.edit_original_message(embed=carregando)
ping = (time.monotonic() - before) * 1000
Embed_De_Ping = disnake.Embed(
title="Status:",
description=f"> - Ping da Websocket: **{round(bot.latency * 1000)}**ms \n > - Ping da Client: **{int(ping)}**ms \n> - Uptime: **{uptimed}**",
color=0x2f3136)
await interaction.edit_original_message(embed=Embed_De_Ping)```
【问题讨论】:
-
用你自己的话来说,你希望
print(uptimed)做什么,为什么?我在这段代码中看到了多个问题。该行代码至少有两处错误,其中一处在另一行中也有错误(这是报告问题的实际原因)。最重要的是,每条text.replace行实际上并没有完成任何事情。我真的认为最好退后一步,确保在尝试编写 Discord 机器人之前正确地学习了基础知识。或者至少阅读ericlippert.com/2014/03/05/how-to-debug-small-programs。 -
(提示:代码中写着
before = time.monotonic(),为什么它不是而是只写before = time.monotonic?如果那样的话会出什么问题?你呢?看看相同的逻辑如何适用于使用uptimed?
标签: python discord.py