繁体   English   中英

如何使用嵌入 webhook 的 discord.py 修复此错误

[英]How to fix this error with discord.py embed in webhooks

我正在尝试制作一个 webhook,但我设法修复了大部分问题,但现在我不断收到此错误,我不知道从哪里开始。

这是错误:

/discordpy-webhook/main.py
Traceback (most recent call last):
  File "/home/ayden/webhook/discordpy-webhook/main.py", line 23, in <module>
    response = webhook.execute()
  File "/home/ayden/.local/lib/python3.7/site-packages/discord_webhook/webhook.py", line 157, in execute
    response = self.api_post_request(url)
  File "/home/ayden/.local/lib/python3.7/site-packages/discord_webhook/webhook.py", line 137, in api_post_request
    timeout=self.timeout)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 519, in request
    prep = self.prepare_request(req)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 462, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/lib/python3/dist-packages/requests/models.py", line 316, in prepare
    self.prepare_body(data, files, json)
  File "/usr/lib/python3/dist-packages/requests/models.py", line 466, in prepare_body
    body = complexjson.dumps(json)
  File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 382, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3/dist-packages/simplejson/encoder.py", line 296, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3/dist-packages/simplejson/encoder.py", line 378, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3/dist-packages/simplejson/encoder.py", line 273, in default
    o.__class__.__name__)
TypeError: Object of type Embed is not JSON serializable

这是文件:

import discord
from discord_webhook import DiscordWebhook

webhook = DiscordWebhook(url='[REDACTED]')

em = discord.Embed(title='Intersoviet Airlines Information Board', description='Welcome to the Intersoviet Airlines Discord! \n Below you will find different links and info to help you get around.')
em.add_field(name='Dont forget to join the group!', value='Here is the ||hyper||link to the [group](https://www.roblox.com/groups/3524494/Intersoviet-Airlines#!/), here you can also buy perks (BC and FC)')
em.add_field(name='Want to fast travel to our perks?', value='This link shoots you over to our [Buisness Class](https://www.roblox.com/catalog/4484201358/Business-Class), and this one goes to our [First Class.](https://www.roblox.com/catalog/1136633425/First-Class)')
em.add_field(name='Want to apply?', value='Head over to our <#538681693674930185> channel for more info.')
em.add_field(name='Hvae a suggestion?', value='Head to our <#538486459062288405> channel and use `-suggest [Suggestion] (the message will be deleted bt dont worry that means it worked)')
em.add_field(name='need to report a bug or staff?', value='Dm one of our High Command members and we will get right on it')
em.add_field(name='Need a list of our High Command members?', value='Overseer - <@442764814020902938> \n Commissar - <@526366627068117010> \n Deputy Commissar - <@597478415481700377> \n Director of Aviation - <@398959101322854400> \n Deputy Director of Aviation - <@640359824844128279>')
em.add_field(name='Want a list of our heads?', value='Head of Ground Crew - N/A \n Head of Air Marshals - <@392236139945263105> \n Head of Flight Attendants - <@805344685647855617> \n Head of Captains - N/A \n\n Have a question about these departments? DM them, they are glad to help!')
em.add_field(name='Thinking of becoming a developer for us?', value='DM the Overseer to apply.')

webhook.add_embed(em)
response = webhook.execute()

如果您能给我任何尝试,那将对我有很大帮助; 我也在使用最新的 discord.py 模块和 python 3.7.3

不确定这是否可行,但给它一个 go

webhook.add_embed(json.dumps(em))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM