我想实现一个玩家地图,以便机器人本身通过枕头绘制它。有一个错误..帮我修复代码以使其正常工作
@client.command(pass_context = True)
async def card(ctx):
await ctx.channel.purge(limit = 1)
img = Image.new('RGBA', (400, 200), '#232529')
url = str(ctx.author.avatar_url)[:-10]
response = requests.get(url, stream = True)
response = Image.open(io.BytesIO(response.content))
response = response.convert('RGBA')
response = response((100, 100), Image.ANTIALIS)
img.paste(response, (15, 15, 115, 115))
idraw = ImageDraw.Draw(img)
name = ctx.author.name
tag = ctx.author.descriminator
headline = ImageFont.truetype('arial.ttf', size = 20)
undertext = ImageFont.truetype('arial.ttf', size = 12)
idraw.text((145, 15), f'{name}#{tag}', font = headline)
idraw.text((145, 50), f'ID: {ctx.author.id}', font = undertext)
img.save('user_card.png')
await ctx.send(file = discord.File(fp = 'user_card.png'))
错误:
Command raised an exception: UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x045CF7F8>
我认为问题在于您的代码中有很多错别字:)
这是我发现的
可能我忘了提点别的,但还有一些评论:
url = str(ctx.author.avatar_url)[:-10]
- 我不太明白你为什么在这里[:-10]
,因为没有它一切都很好@client.command(pass_context = True)
- 在新版本的 discord 命令中,无需指定pass_context
. 后面只有括号command
我稍微更改了代码,它似乎可以工作:
结果: