簡體   English   中英

Discord.py:嵌入作者返回嵌入。編輯時為空

[英]Discord.py: Embed author returning embed.Empty on edit

在處理我的編輯嵌入命令時,我遇到了一個問題。 除了作者之外,一切都按預期工作。 在編輯嵌入的作者時,如果在原版中它是空的,則在編輯后機器人會用“embed.Empty”填充它,而不是讓它空着。 但是,如果在原作者中有一個值,則機器人不會像預期的那樣更改它。 我附上了一張圖片,所以你也可以明白我的意思。

在這里,您可以看到機器人在作者字段中放置“embed.Empty”的位置。

  @embed.command()
  @commands.has_permissions(manage_permissions = True) 
  @commands.bot_has_permissions(manage_permissions = True)
  async def edit(self, ctx, msgID: discord.Message):
    await ctx.send('What part of the embed would you like to edit? The `title`, `body`, `footer`, `color`, `image`, `thumbnail`, `author name`, or `author icon`?')

    og_embed = msgID.embeds[0]
    og_embed_footer = msgID.embeds[0].footer
    og_embed_image = msgID.embeds[0].image
    og_embed_thumbnail = msgID.embeds[0].thumbnail
    og_embed_author = msgID.embeds[0].author

    def check(m):
      return m.channel == ctx.channel and m.author == ctx.author

    while True:
        try:
            msg = await self.bot.wait_for('message', check=check, timeout=30.0)

            if str(msg.content) == 'title':
              await ctx.send('What should the new title of the embed be?')
              new_title_input = await self.bot.wait_for('message', check=check, timeout=30.0)
              new_embed=discord.Embed(title=new_title_input.content, description=og_embed.description, color=og_embed.color)
              new_embed.set_footer(text=og_embed_footer.name)
              new_embed.set_image(url=og_embed_image.url)
              new_embed.set_thumbnail(url=og_embed_thumbnail.url)
              new_embed.set_author(name=og_embed_author.name, icon_url=og_embed_author.icon_url)
              await msgID.edit(content=None, embed=new_embed)

            elif str(msg.content) == 'body':
              await ctx.send('You chose to edit the body.')

        except asyncio.TimeoutError:
            return

我不知道為什么會這樣,並且沒有錯誤被排除。

感謝 Abdulaziz 和 NuKeFluffy 的幫助,我先放入了一些 if 語句來檢查該字段是否為空,如果為空則保持原樣(:這是新代碼:

  @embed.command()
  @commands.has_permissions(manage_permissions = True) 
  @commands.bot_has_permissions(manage_permissions = True)
  async def edit(self, ctx, msgID: discord.Message):
    await ctx.send('What part of the embed would you like to edit? The `title`, `body`, `footer`, `color`, `image`, `thumbnail`, `author name`, or `author icon`?')

    og_embed = msgID.embeds[0]
    og_embed_footer = msgID.embeds[0].footer
    og_embed_image = msgID.embeds[0].image
    og_embed_thumbnail = msgID.embeds[0].thumbnail
    og_embed_author = msgID.embeds[0].author

    def check(m):
      return m.channel == ctx.channel and m.author == ctx.author

    while True:
        try:
            msg = await self.bot.wait_for('message', check=check, timeout=30.0)

            if str(msg.content) == 'title':
              await ctx.send('What should the new title of the embed be?')
              new_title_input = await self.bot.wait_for('message', check=check, timeout=30.0)

              # The one being changed here
              new_embed=discord.Embed(title=new_title_input.content, description=og_embed.description, color=og_embed.color)
              
              if (og_embed_footer.text != discord.Embed.Empty):
                new_embed.set_footer(text=og_embed_footer.text)

              new_embed.set_image(url=og_embed_image.url)

              new_embed.set_thumbnail(url=og_embed_thumbnail.url)

              if (og_embed_author.name != discord.Embed.Empty):
                new_embed.set_author(name=og_embed_author.name, icon_url=og_embed_author.icon_url)

              await msgID.edit(content=None, embed=new_embed)
              return

            elif str(msg.content) == 'body':
              await ctx.send('You chose to edit the body.')

        except asyncio.TimeoutError:
            return

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM