所以我在图片中有一个嵌入,我想从那个嵌入中获取用户 ID,有什么办法吗?
到目前为止我尝试了什么:
to_dict With Discord.py, is there a way to read embedded messages? 无法获取字段的值
.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 无效,需要我更改值
答案 0 :(得分:2)
set_field_at()
是一个更新字段内容的函数。您将无法使用此方法检索内容。
您仍然可以使用 .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()
- 表示字段的属性