![](/img/trans.png)
[英]Is there a way for my discord.py embed field name and value be aligned
[英]Is there a way to read a value of a specific field in an embed discord.py
所以我在图片中有一个嵌入,我想从那个嵌入中获取用户 ID,有什么办法吗?
到目前为止我尝试了什么:
to_dict 和 Discord.py,有没有办法读取嵌入的消息? 无法获取该字段的值
.fields https://discordpy.readthedocs.io/en/latest/api.html?highlight=# discord.Embed.fields 结果与 to_dict 相同
.set_field_at https://discordpy.readthedocs.io/en/latest/api.html?highlight=#discord.Embed.set_field_at不起作用,需要我更改值
set_field_at()
是一个 function 将更新字段的内容。 您将无法使用此方法检索内容。
您仍然可以使用.fields
。 您可以在您选择的方法中放入类似于以下内容的内容。
embed = # Put the Embed in the picture as a discord.Embed object and assign it to this variable
for field in embed.fields: # Dynamically get the user id field.
if field.name.lower() == "user id": # I recommend copying and pasting the field of choice, just in case the characters are not the same visually.
user_id_field = field
break
else: # In case the field isn't found
pass # Put some code here
user_id = int(user_id_field.value) # Get the value of the field
# Either send or print it
参考:
discord.Embed.fields
- 从嵌入中获取字段列表。discord.Embed.add_field()
- 表示来自字段的属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.