【问题标题】:Deleting and editing messages/embeds with discord components删除和编辑带有不和谐组件的消息/嵌入
【发布时间】:2021-10-06 09:56:12
【问题描述】:

我最近一直在搞乱组件...截至目前,我正试图让两个独立的组件对它们所应用的消息做一些事情。 Delete 删除消息 Approve 编辑消息(这是一个嵌入)并且什么都不做。 如您所见,我应用这些组件的消息称为firstmessage

可以,是的,但是有一个小问题......

如果有 f.ex 其中两个 firstmessage 嵌入到单独的消息中,我单击其中一个 Delete,它们都会被删除。当我单击Approve 时,这同样适用于它们。这是我目前唯一的问题。

代码:

firstmessage = await channel.send(
embed=firstembed,
components=[[Button(style=3, label="Approve"),Button(style=4, label="Delete")]
])

interaction = await self.bot.wait_for("button_click")

if interaction.component.label.startswith("Approve"):
    await firstmessage.edit(embed=approved, components=[]) # here I edit firstmessage upon clicking
    pass

elif interaction.component.label.startswith("Delete"):
    await firstmessage.delete() # here I delete firstmessage upon clicking
    pass

感谢您的帮助和提示!

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    Discord Python button press triggers all buttons in a command

    我回答了这个问题。您的问题与此类似。

    根据您的情况,您应该将代码更改为:

    
    firstmessage = await channel.send(
    embed=firstembed,
    components=[[Button(style=3, label="Approve"),Button(style=4, label="Delete")]
    ])
    # The following code is new
    def check(res):
      return res.message = firstmessage # Checks if the message sent is the message that was interacted
    # The above code is new
    interaction = await self.bot.wait_for("button_click",check=check)
    
    if interaction.component.label.startswith("Approve"):
        await firstmessage.edit(embed=approved, components=[]) # here I edit firstmessage upon clicking
        pass
    
    elif interaction.component.label.startswith("Delete"):
        await firstmessage.delete() # here I delete firstmessage upon clicking
        pass
    

    【讨论】:

      猜你喜欢
      • 2021-12-03
      • 2021-02-01
      • 2019-10-11
      • 2020-07-09
      • 2021-07-29
      • 2018-11-21
      • 1970-01-01
      • 2021-07-06
      • 1970-01-01
      相关资源
      最近更新 更多