有没有办法在嵌入的 discord.py 中读取特定字段的值

时间:2021-05-15 16:20:53

标签: python discord.py

Embed

所以我在图片中有一个嵌入,我想从那个嵌入中获取用户 ID,有什么办法吗?

到目前为止我尝试了什么:

1 个答案:

答案 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

参考: