【问题标题】:Logging messages with discord.py bot [duplicate]使用 discord.py bot 记录消息 [重复]
【发布时间】:2021-12-30 03:59:51
【问题描述】:

我正在尝试向我的机器人添加日志记录功能

我试图让程序输出文本,但它输出的是对象引用

@bot.event
async def on_message(message: str):
    ts = time.time()
    st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
    with open("logs.txt", "a") as text_file:
        print(f"<{st}> {message}", file=text_file)

我期待这样的事情 如果消息是“你好”在 2019-06-08 17:32 它会输出

<2019-06-08 17:32:26> hello

但确实如此

<2019-06-08 17:24:26> <discord.message.Message object at 0x0083C0A8>

【问题讨论】:

  • 好吧,message 显然不是 str 对象 ;)

标签: python discord discord.py


【解决方案1】:
print(f"<{st}> {message.content}", file=text_file)

【讨论】:

    猜你喜欢
    • 2021-05-17
    • 2021-12-04
    • 1970-01-01
    • 2021-08-23
    • 2021-03-17
    • 2021-08-11
    • 2020-09-11
    • 2018-05-01
    • 2021-10-04
    相关资源
    最近更新 更多