def convert(self, ctx, argument):
# Scan attached images.
if argument == 'attached':
for attachment in ctx.message.attachments:
if attachment.height:
return attachment.proxy_url
# Scan channel for any recent images.
if argument == 'recent':
result = await _get_recent_image(ctx.channel)
if not result:
raise commands.BadArgument('No recent image was found in this channel.')
return result
try:
# Resolve avatar.
user = await UserConverter().convert(ctx, argument)
return user.avatar_url_as(format='png')
except commands.BadArgument:
pass
# ok image
if any(argument.startswith(safe_url) for safe_url in SAFE_IMAGE_HOSTS):
return argument
error = ("Invalid image URL or user. To use a recent image from this channel, specify `recent`. You can also "
"attach any image and specify `attached` to use that image.")
raise commands.BadArgument(error)
评论列表
文章目录