【问题标题】:Discord.py | Pillow ImageFilter不和谐.py |枕头图像过滤器
【发布时间】:2021-10-03 12:31:53
【问题描述】:

代码任务
使用该命令时,机器人会拍摄用户或用户标记的照片并添加模糊效果。

我的代码问题
在查看了很多资源以完成我的任务后,我找不到详细的答案。在我看来,我的代码看起来不错,但它不起作用,尽管没有输出错误。

代码:

from PIL import Image, ImageFilter

@Bot.command()
async def blur(ctx, user: discord.Member = None):
    async with ctx.channel.typing():
        await ctx.message.delete()
        url = user.avatar_url
        image = Image.open(url)
        blurred_url = image.filter(ImageFilter.BLUR)
        blurred_url.save("sas.png")
        file = discord.File("sas.png", filename="sas.png")
        await ctx.send(file=file)

【问题讨论】:

    标签: discord.py python-imaging-library imagefilter


    【解决方案1】:

    这是我的问题的解决方案:

    import discord
    from discord.ext import commands
    from PIL import Image, ImageFilter
    from urllib.request import Request, urlopen
    
    Bot = commands.Bot(command_prefix='!', intents = discord.Intents.all())
    
    @Bot.command()
    async def blur(ctx, user: discord.Member = None):
        if user is None: user = ctx.author
        async with ctx.channel.typing():
            await ctx.message.delete()
            url = user.avatar_url
            req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
            resource = urlopen(req)
            avatar = open("avatar.png", 'wb')
            avatar.write(resource.read())
            avatar.close()
            image = Image.open('avatar.png')
            blurred_url = image.filter(ImageFilter.BLUR)
            blurred_url.save("sas.png")
            file = discord.File("sas.png", filename="sas.png")
            await ctx.send(file=file)
    
    Bot.run('TOKEN')
    

    我还没有解决问题。所以我不知道我是否可以帮助您解决与代码相关的问题。祝你好运。祝你好运。

    代码正在运行

    【讨论】:

      猜你喜欢
      • 2020-03-28
      • 1970-01-01
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多