所以每当我使用我的cog时,我都会收到“意外缩进”错误..
我一直试图修复它一段时间但它仍然无法正常工作..
代码:
@commands.command(pass_context=True)
async def magik(self, ctx, url, url2=None):
"""Apply magik to Image(s)\n .magik image_url or .magik image_url image_url_2"""
try:
print(url)
extensions = ['.png', '.jpg', '.jpeg', '.JPG', '.PNG', '.JPEG']
if any(x in url for x in extensions) and url2 is None:
await self.bot.say("ok, applying magik")
with aiohttp.ClientSession() as session:
location = '/root/discord/files/magik.jpg'
async with session.get(url) as resp:
data = await resp.read()
with open(location, "wb") as f:
f.write(data)
elif url2 is not None and any(x in url2 for x in extensions):
await self.bot.say("ok, applying magik")
with aiohttp.ClientSession() as session:
location = '/root/discord/files/magik.jpg'
location2 = '/root/discord/files/magik2.jpg'
async with session.get(url) as resp:
data = await resp.read()
with open(location, "wb") as f:
f.write(data)
async with session.get(url2) as resp:
data = await resp.read()
with open(location2, "wb") as f:
f.write(data)
else:
await self.bot.say("Not an image!")
return
exif = {}
image = wand.image.Image(filename='/root/discord/files/magik.jpg')
exif.update((k[5:], v) for k, v in image.metadata.items()
if k.startswith('exif:'))
if url2 is not None:
exif2 = {}
image2 = wand.image.Image(filename='/root/discord/files/magik2.jpg')
exif2.update((k[5:], v) for k, v in image2.metadata.items()
if k.startswith('exif:'))
img = wand.image.Image(filename='/root/discord/files/magik.jpg')
print(img.size)
i = img.clone()
r = random.randint(1,4)
if url2 is not None:
with wand.image.Image(filename='/root/discord/files/magik2.jpg') as B:
B.clone()
B.liquid_rescale(width=int(B.width*0.5), height=int(B.height*0.5), delta_x=1, rigidity=0)
B.liquid_rescale(width=int(B.width*1.5), height=int(B.height*1.5), delta_x=2, rigidity=0)
with wand.image.Image(filename='/root/discord/files/magik.jpg') as A:
A.clone()
A.transform(resize='800x800>')
A.liquid_rescale(width=int(A.width*0.5), height=int(A.height*0.5), delta_x=1, rigidity=0)
A.liquid_rescale(width=int(A.width*1.5), height=int(A.height*1.5), delta_x=2, rigidity=0)
A.resize(A.width, A.height)
A.composite_channel('default_channels', A, 'over', 0, 0 )
A.composite_channel('default_channels', B, 'over', 0, 0 )
A.save(filename='/root/discord/files/magik_.png')
else:
params = random.uniform(0.5, 2)
i.transform(resize='800x800>')
i.liquid_rescale(width=int(i.width*0.5), height=int(i.height*0.5), delta_x=1, rigidity=0)
i.liquid_rescale(width=int(i.width*1.5), height=int(i.height*1.5), delta_x=2, rigidity=0)
i.resize(i.width, i.height)
# i.rotate(90 * r)
# i.negate()
i.save(filename='/root/discord/files/magik_.png')
print(exif)
if len(str(exif)) <= 2000 and url2 is None:
await self.bot.say("Exif Data: ```{0}```".format(str(exif)))
elif url2 is not None and len(str(exif)) <= 2000 and len(str(exif2)) <= 2000:
await self.bot.say("Exif Data Image 1: ```{0}```".format(str(exif)))
await self.bot.say("Exif Data Image 2: ```{0}```".format(str(exif2)))
else:
await self.bot.say("Exif Data too long, truncated")
await self.bot.send_file(ctx.message.channel, '/root/discord/files/magik_.png')
except Exception as e:
await self.bot.say(code.format(type(e).__name__ + ': ' + str(e)))
帮助很感激,因为我无法解决此错误。
答案 0 :(得分:0)
使用混合制表符和空格可能存在问题。根据您使用的编辑器,您可能需要转到编辑器首选项并建立一种方法来设置&#34;选项卡作为空格&#34;。