Discord.py:嵌入作者在编辑时返回 embed.Empty
Discord.py: Embed author returning embed.Empty on edit
在处理我的编辑嵌入命令时,我遇到了一个问题。除作者外,一切都按预期工作。编辑嵌入的作者时,如果在原始版本中它是空的,则在编辑后机器人会用 '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
在处理我的编辑嵌入命令时,我遇到了一个问题。除作者外,一切都按预期工作。编辑嵌入的作者时,如果在原始版本中它是空的,则在编辑后机器人会用 '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