Когда я создаю вставку с помощью pycord и устанавливаю миниатюру на фактическое изображение профиля, функция работает нормально, но когда для нее установлено изображение профиля Discord по умолчанию, она выдает эту ошибку:
Ignoring exception in command checktime:
Traceback (most recent call last):
File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\commands\core.py", line 113, in wrapped
ret = await coro(arg)
File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\commands\core.py", line 766, in _invoke
await self.callback(ctx, **kwargs)
File "C:\Users\Owner\Desktop\Coding\DiscordBots\Time_Bot_Discord.py", line 63, in checktime
await ctx.respond(embed=embed)
File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\interactions.py", line 643, in send_message
await adapter.create_interaction_response(
File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\webhook\async_.py", line 213, in request
raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In data.embeds.0.thumbnail.url: Scheme "none" is not supported. Scheme must be one of ('http', 'https').
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\bot.py", line 755, in process_application_commands
await ctx.command.invoke(ctx)
File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\commands\core.py", line 312, in invoke
await injected(ctx)
File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\commands\core.py", line 119, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.commands.errors.ApplicationCommandInvokeError: Application Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In data.embeds.0.thumbnail.url: Scheme "none" is not supported. Scheme must be one of ('http', 'https').
Код функции:
@bot.slash_command(name='checktime', description='Check the time that someone is online')
async def checktime(ctx, member: discord.Option(discord.Member, "Enter someone", required=True)):
global act_list
print(member) # debug
if not await cooldown(ctx, ctx.author, 4, 1):
return
embed = discord.Embed(title=f"Checking time of... {member.display_name}",
description=f"Percent of time: {((sum(act_list[member][3], timedelta())).total_seconds()) / ((datetime.now() - start_time).total_seconds()) * 100: .2f}%")
try:
embed.set_thumbnail(url=member.avatar)
except:
embed.remove_thumbnail()
embed.set_thumbnail(url=member.default_avatar)
embed.add_field(name = "Start Time", value=start_time.strftime("%H:%M:%S" + " UTC" + " at %Y-%m-%d"))
embed.set_footer(text = "Note: Bot is in experimental phase, and times may reset during the day.\nAll data is not fully accurate.")
await ctx.respond(embed=embed)
act_list[ctx.author][2][1] = datetime.now()
Как я могу это исправить?
Эта ошибка означает, что им нужен URL-адрес, например https//mydomain.com/mypicture.png
, для миниатюры встраивания, что возможно с помощью member.avatar.url
Кроме того, аватар участника может быть None
или member
не имеет пользовательского аватара. Так что вы должны проверить display_avatar
.
Вы должны заменить try-catch на это:
embed.set_thumbnail(url=str(member.display_avatar.url))
Простой, легкий и однострочный.