【问题标题】:Create a discord bot which logs all messages创建一个记录所有消息的不和谐机器人
【发布时间】:2018-06-23 03:43:03
【问题描述】:

所以我研究了创建一个 python discord 机器人,并且想知道如何创建一个记录所有内容的 discord 机器人。我希望它立即将消息、编辑、删除、邀请等记录到文本文件中。我看到了 .on_message() 但我不知道如何实际获取消息。有什么想法吗?(这样做的目的是为学校俱乐部不和谐服务器创建一个日志,允许教师加入。除非他们有一种检查教师和学生之间所有通信的方法,否则他们不能加入。这个机器人将在学校服务器)

提前致谢。

【问题讨论】:

    标签: python discord


    【解决方案1】:

    我建议查看Clientdocumentation,因为所有编辑、删除、邀请都将通过客户端进行记录。我无法直接使用代码,因为我使用的是 .js 而不是 .py

    【讨论】:

      【解决方案2】:

      说实话,写入电子表格或数据库可能更容易

      我最近制作了一个机器人来执行此操作,并将所有消息上传到 Google 表格。你可以check it out here。如果您仍然想自己制作,可以使用

      @bot.event
      async def on_message(message):
          author = str(message.author)
          content = str(message.content)
          userid = str(message.author.id) 
          messageid = str(message.id)
          time = str(message.created_at)
          link = str(message.jump_url)
          channel = str(message.channel)
          row = [userid,author,content,time,messageid,link,channel]
      

      然后将行写入电子表格或 txt 文件以记录消息

      @bot.event
      async def on_message_edit(before, after):
          row = [before, after]
      

      然后将行写入电子表格或 txt 文件

      @bot.event
      async def on_message_delete(message):
          message = message
      

      然后将消息写入消息。

      有关将消息写入文件的更多信息,

      Python Input/Output docs 用于 txt 文件

      Python JSON docs 用于 JSON 文件

      GSpread documentation 用于 Google 表格

      SQLite Documentation 用于数据库文件

      【讨论】:

        猜你喜欢
        • 2018-11-19
        • 2020-11-25
        • 2020-11-29
        • 2020-04-21
        • 1970-01-01
        • 2018-05-02
        • 2020-10-03
        • 1970-01-01
        • 2021-05-09
        相关资源
        最近更新 更多