【问题标题】:"<function status.<locals>.uptimed at 0x000001C35A56FE20>", What is this?“<function status.<locals>.uptimed at 0x000001C35A56FE20>”,这是什么?
【发布时间】:2022-07-18 10:15:34
【问题描述】:

当我使用 disnake 编写我的不和谐机器人时,当我使用 /status 时,正常运行时间不会显示所有需要的信息,而是:&lt;function status.&lt;locals&gt;.uptimed at 0x000001C35A56FE20&gt; 发生了什么,以及如何解决它?

代码:

@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


【解决方案1】:

问题出在这里:

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)

更具体地说,这是:Uptime: **{uptimed}**"uptimed 是一个函数,你好像忘了调用它。应该是uptimed()。输出一个函数而不调用它只会打印它的内存地址。

【讨论】:

    猜你喜欢
    • 2017-02-27
    • 2013-10-20
    • 2022-12-18
    • 2013-03-24
    • 1970-01-01
    • 2012-12-26
    • 2019-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多