简体   繁体   English

Discord.py:嵌入作者返回嵌入。编辑时为空

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

when working on my edit embed command, I came across an issue.在处理我的编辑嵌入命令时,我遇到了一个问题。 Everything works as intended except for the author.除了作者之外,一切都按预期工作。 When editing the author of the embed, if in the original it is empty, after editing the bot fills it with 'embed.Empty' instead of just leaving it empty.在编辑嵌入的作者时,如果在原版中它是空的,则在编辑后机器人会用“embed.Empty”填充它,而不是让它空着。 However, if in the original the author has a value, the bot does not change it, like intended.但是,如果在原作者中有一个值,则机器人不会像预期的那样更改它。 I've attached an image so you can see what I mean too.我附上了一张图片,所以你也可以明白我的意思。

在这里,您可以看到机器人在作者字段中放置“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

I don't know why this is happening, and no errors are put out.我不知道为什么会这样,并且没有错误被排除。

Thanks to the help of Abdulaziz and NuKeFluffy, I put in some if-statements to check if the field was empty first, and leave it that way if it was (: Here is the new code:感谢 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