【发布时间】:2022-01-14 06:21:31
【问题描述】:
我正在尝试从名为 http://discohook.org 的站点获取 json
然后我希望能够将它生成的 json 放入一个不和谐的命令中,以便机器人随后作为嵌入消息发布。
这是我的代码:
payload = message.content.strip("$embed ")
embed = Embed.from_dict(json.loads(payload))
await message.channel.send(embed=embed)
json 看起来像这样:
{
"content": null,
"embeds": [
{
"title": "Testy Test",
"description": "Hello World!",
"color": 16711680,
"footer": {
"text": "I hope this works"
},
"timestamp": "2021-12-09T11:36:00.000Z"
}
]
}
但是,当我将命令与上述 json(或任何其他看似有效的 json)一起使用时,我收到错误
Traceback (most recent call last):
File "D:\Dev\London-RP\lrp-bot\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "D:\Dev\London-RP\lrp-bot\_Project\lrp-bot\main.py", line 116, in on_message
await message.channel.send(embed=embed)
File "D:\Dev\London-RP\lrp-bot\lib\site-packages\discord_slash\dpy_overrides.py", line 323, in send_override
return await send(channel, *args, **kwargs)
File "D:\Dev\London-RP\lrp-bot\lib\site-packages\discord_slash\dpy_overrides.py", line 300, in send
data = await state.http.send_message(
File "D:\Dev\London-RP\lrp-bot\lib\site-packages\discord\http.py", line 254, in request
raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50006): Cannot send an empty message
任何正确方向的帮助将不胜感激! (编辑:包含完整错误)
【问题讨论】:
-
始终将完整的错误消息(从单词“Traceback”开始)作为文本(不是屏幕截图,不是指向外部门户的链接)(不是在 cmets 中)。还有其他有用的信息。
-
你检查过你在变量中得到了什么吗?也许你真的有空变量。或者它可能需要其他东西来发送它。你只有
footer text,但没有message text -
类似的 Discord.py discord.Embed.from_dict not creating an embed properly 但示例 JSON 有
fields和name、value。也许你也需要它。或者,也许您需要其他元素 - 例如image或video -
@furas 我已经编辑包含完整的错误,很抱歉第一次没有包含它。
标签: python json discord discord.py