首页 > 解决方案 > 'Vouch' 的实例没有'user' 成员

问题描述

两个代码都有相同的错误。“'Vouch' 的实例没有 'user' 成员”。它是 discord.py 的担保机器人

    @check(is_bot_owner)
    async def name(self, ctx, *, new_name: str):
        """Vouch Bot"""
        await self.user.edit(username=new_name)
        await ctx.send(no_ping("Changed name to {}.".format(new_name)))

@command()
    @check(is_bot_owner)
    async def avatar(self, ctx):
        """Insert The Bot Avatar Here"""
        att = ctx.message.attachments
        if len(att) == 1:
            async with aiohttp.ClientSession() as session:
                async with session.get(att[0].proxy_url) as resp:
                    avatar = await resp.read()
                    await self.user.edit(avatar=avatar)
                    await ctx.send("Avatar changed.")

   

标签: pythondiscord.py

解决方案


self.bot.user(或者self.client.user,取决于你如何命名它)不是self.user

await self.bot.user.edit(...) # Or self.client.user.edit

avatar此外,无需每次调用​​命令时都创建新会话,您可以简单地下载图像Attachment.read

att = ctx.message.attachments
if len(att) == 1:
    f = await att[0].read()
    await self.bot.user.edit(avatar=f) # Or self.client.user.edit

此外,如果您打算在aiohttp每次调用命令时创建一个新会话是一个坏主意,那么您应该始终只打开一个会话来完全执行请求。


推荐阅读