我正在执行像素命令,当我输入命令时遇到了一个问题:AttributeError: 'Member' object does not have attribute 'avatar_as

问题描述 投票:0回答:1

代码:

from discord.ext import commands

@commands.command()
    @commands.cooldown(rate=1, per=10.0, type=commands.BucketType.user)
    async def pixel(self, ctx, user=None):
        """Pixelates an image."""
        if user is None:
            for attachment in ctx.message.attachments:
                img = await self.bot.dagpi.image_process(
                    asyncdagpi.ImageFeatures.pixel(), attachment.proxy_url
                )
                file = discord.File(fp=img.image, filename=f"pixel.{img.format}")
                await ctx.send(file=file)

        else:
            userID = re.sub("[^0-9]", "", user)
            try:
                user = await ctx.guild.fetch_member(userID)
            except BaseException:
                await ctx.send("No user found.")
                return

            url = str(user.avatar_as(format="png", size=1024))
            img = await self.bot.dagpi.image_process(
                asyncdagpi.ImageFeatures.pixel(), url
            )
            file = discord.File(fp=img.image, filename=f"pixel.{img.format}")
            await ctx.send(file=file)

我尝试用 avatar_us 替换 avatar_url_as,没有任何改变。

请您更正我的代码,并写下答案,我将不胜感激

discord.py bots pixel
1个回答
1
投票

迁移到discord 2.0时,

Member.avatar_url_as
Member.avatar.replace
取代。

另请注意,如果没有头像,您可能还需要

Member.default_avatar.replace

© www.soinside.com 2019 - 2024. All rights reserved.