【发布时间】:2021-04-01 13:04:40
【问题描述】:
在处理我的编辑嵌入命令时,我遇到了一个问题。除作者外,一切都按预期工作。在编辑嵌入的作者时,如果在原版中它是空的,则在编辑后机器人会用“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
我不知道为什么会发生这种情况,并且没有出现错误。
【问题讨论】:
-
为什么不直接使用 if 语句来检查作者字段是否为空?
-
我尝试使用
if og_embed_author != None or 'Embed.Empty':,但仍然遇到同样的问题。似乎现在页脚也发生了这种情况,但方式相反。 -
添加到@NuKeFluffy 评论使用
\u200b作为新值,它将只是一个空行。 -
你的 if 语句应该是这样的:
if (og_embed_author.name != discord.Embed.Empty): -
您将 'Embed.Empty' 放在一个字符串中,但它是一个不和谐的嵌入对象,因此将其更改为
discord.Embed.Empty即可
标签: python discord discord.py embed discord.py-rewrite