【问题标题】:send json as inline using discord.py使用 discord.py 将 json 作为内联发送
【发布时间】:2021-07-05 11:48:02
【问题描述】:

我在 python 中开发了我自己的 discord 机器人,我遇到了如何使用命令显示 json 嵌入消息的当前问题。 我没有使用 js 的经验,为了创建嵌入,我使用了 https://discord.club/,因为它基于图形界面。 而且我找不到在 discord.py 中嵌入 json 的方法

这是json文件本身

{
  "username": "",
  "avatar_url": "",
  "content": "@here",
  "embeds": [
    {
      "title": "__Installation and Start-Up__",
      "color": 16514816,
      "description": "1. Install [vcredist](https://aka.ms/vs/16/release/vc_redist.x64.exe)\n2. Turn your antivirus on and add `Disturbed.exe` and the folder it's in to your antivirus or Windows Defender exceptions.\n3. Make sure background programs such as RAM cleaners (MSI Afterburner & CCleaner) don't interfere with the injection process.\n4. Make sure your GTA V is on the latest version.\n5. Run the game and start the injector. Wait for the game to fully load offline/online, then inject.",
      "timestamp": "",
      "url": "",
      "author": {
        "url": ""
      },
      "image": {
        "url": ""
      },
      "thumbnail": {
        "url": ""
      },
      "footer": {
        "text": "",
        "icon_url": ""
      },
      "fields": []
    }
  ],
  "components": []
}

【问题讨论】:

    标签: javascript python-3.x discord.py


    【解决方案1】:

    使用Embed.from_dict 类方法

    embed_dict = {
      "username": "",
      "avatar_url": "",
      "content": "@here",
      "embeds": [
        {
          "title": "__Installation and Start-Up__",
          "color": 16514816,
          "description": "1. Install [vcredist](https://aka.ms/vs/16/release/vc_redist.x64.exe)\n2. Turn your antivirus on and add `Disturbed.exe` and the folder it's in to your antivirus or Windows Defender exceptions.\n3. Make sure background programs such as RAM cleaners (MSI Afterburner & CCleaner) don't interfere with the injection process.\n4. Make sure your GTA V is on the latest version.\n5. Run the game and start the injector. Wait for the game to fully load offline/online, then inject.",
          "timestamp": "",
          "url": "",
          "author": {
            "url": ""
          },
          "image": {
            "url": ""
          },
          "thumbnail": {
            "url": ""
          },
          "footer": {
            "text": "",
            "icon_url": ""
          },
          "fields": []
        }
      ],
      "components": []
    }
    
    embed = discord.Embed.from_dict(embed_dict['embeds'][0])
    await ctx.send(embed=embed)
    

    请记住,您一次只能发送 一个与机器人一起嵌入

    【讨论】:

      【解决方案2】:

      查看文档中的discord.Embed.from_dict(data)

      【讨论】:

        猜你喜欢
        • 2020-12-24
        • 1970-01-01
        • 1970-01-01
        • 2019-03-19
        • 1970-01-01
        • 2012-02-28
        • 2023-01-30
        • 2016-09-24
        • 1970-01-01
        相关资源
        最近更新 更多