【问题标题】:Discord.py Interaction FailedDiscord.py 交互失败
【发布时间】:2021-10-29 18:41:24
【问题描述】:

所以我正在制作一个 Discord 机器人,而且我对它的 API 还比较陌生。我希望按钮能够在不向用户发送消息或任何形式的响应的情况下编辑嵌入。但是,如果我尝试发送空响应或根本没有响应,则每次单击按钮时都会显示“此交互失败”。如果我添加诸如 content = 'text' 之类的内容来响应它可以工作,但我不想发送任何东西。这是我的代码:

 @commands.command()
  async def assist(self, ctx):
    embed = discord.Embed(title = 'Commands', description = 'sdgsdgsdgds', color = 0x0099ff)
    message =  await ctx.send(
      embed = embed,
      components = self.buttons
      )
    while True:
      event = await self.client.wait_for('button_click')
      if event.channel is not ctx.channel:
        return
      if event.channel == ctx.channel:
        response = event.component.id
        if response is None:
          await event.channel.send('Something went wrong. Please try again.')
        if event.channel == ctx.channel:
          if response == '1':
            await message.edit(embed = discord.Embed(title = 'New', description = 'HDFGSFGS'))
            await event.respond()

【问题讨论】:

  • 我不相信“button_click”是一个有效的 discord.py 事件,你应该定义一个按钮回调:discordpy.readthedocs.io/en/master/…
  • 它是,所有的代码我只需要一个解决方案来解决我提出的问题。最后一行,即只有在我等待 event.respond(content = 'message') 时才有效。但是,我不想在用户每次单击按钮时都向他们发送消息,以产生有效的交互。
  • 您找到解决方案了吗?

标签: python discord bots interaction


【解决方案1】:

我在官方文档上找到了解决办法

while True:
      event = await self.client.wait_for('button_click')
      if event.channel is not ctx.channel:
        return
      if event.channel == ctx.channel:
        response = event.component.id
        if response is None:
          await event.channel.send('Something went wrong. Please try again.')
        if event.channel == ctx.channel:
          if response == '1':
            await event.edit_origin(
               embed = discord.Embed(title = 'New', description = 'HDFGSFGS')
            )

【讨论】:

    猜你喜欢
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 2021-10-22
    • 2022-01-19
    • 2023-03-16
    • 2011-08-23
    • 2021-12-22
    • 1970-01-01
    相关资源
    最近更新 更多