【问题标题】:Discord Bot Buttons MessagesDiscord Bot 按钮消息
【发布时间】:2021-08-27 00:38:57
【问题描述】:

我怎样才能做到这一点,以便当提到的人按下一个按钮时,它会发送正下方的消息,而当我按下另一个按钮时它会发送另一个留言

@bot.command()
async def Pancakes(ctx, user : discord.Member):
    Pancakes=discord.Embed(title="Pancakes", description=f" **{ctx.author.mention} a offert des Pancakes à {user.mention} !**", color=0xFF5733)
    image = random.choice([''])
    Pancakes.set_image(url=image)
    Pancakes.set_footer(text = random.choice(funFact))
    Pancakes.set_thumbnail(url = "")
    await ctx.send(embed=Pancakes)

    components = [
    [Button(style=ButtonStyle.gray, label = "Miam !"),
    Button(style=ButtonStyle.gray, label = "Berk !")]
    ]

    Message = await ctx.send(f'**{user.mention}, Do you accept his pancakes ?**', components=components)

【问题讨论】:

  • 我亲爱的老兄,按钮 API 仍然是一个新概念,它有很多错误并且没有关于它的实际文档。你最好等待discord.py 2.0
  • 好的,谢谢,但我们可以对反应做同样的事情吗?
  • 是的,我们可以。唯一的尊重,而不是使用文字,你将不得不使用表情符号

标签: python discord


【解决方案1】:

为了不收到错误消息,您必须发送响应,例如:

    @bot.command()
    async def Pancakes(ctx, user: discord.Member):
        Pancakes = discord.Embed(title="Pancakes", description=f" **{ctx.author.mention} a offert des Pancakes à {user.mention} !**", color=0xFF5733)
        image = random.choice([''])
        Pancakes.set_image(url=image)
        Pancakes.set_footer(text=random.choice(funFact))
        Pancakes.set_thumbnail(url="")
        await ctx.send(embed=Pancakes)

        components = [
            [Button(style=ButtonStyle.gray, label="Miam !"),
             Button(style=ButtonStyle.gray, label="Berk !")]
        ]

        Message = await ctx.send(f'**{user.mention}, Do you accept his pancakes ?**', components=components)
        event= await self.client.wait_for('button_click')

        await event.respond(type=6)

“client.wait_for()”函数会等待名为“click button”的动作。如果检测到此类事件,将发送“DeferredUpdateMessage”响应确认事件成功。

【讨论】:

    猜你喜欢
    • 2019-07-04
    • 2021-03-27
    • 2021-08-12
    • 2021-10-30
    • 2020-12-01
    • 2021-03-02
    • 2021-01-12
    • 2021-06-05
    • 2018-07-07
    相关资源
    最近更新 更多