python - '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.")
解决方案
它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
每次调用命令时创建一个新会话是一个坏主意,那么您应该始终只打开一个会话来完全执行请求。
推荐阅读
- google-chrome-extension - 如何在 Chrome DevTools 中查看/编辑 localStorage 和 IndexedDB 数据
- python - 如何在 Python 中将 ABC 表示法的音乐文件转换为 midi 或 mp3
- python - ValueError:层顺序的输入0与层不兼容(重塑错误)
- javascript - React - 有一个列表,但不能用它做任何事情
- rust - 为什么我的扩展特性没有被 Cursor 识别?
- wordpress - Woocommerce 正常价格未更新
- apache - .htaccess 重写到文件名存在但扩展名省略的 uri
- windows - 如何通过批处理删除文本文件的重复部分?
- ubuntu - 为什么 rsync 与跳转主机和 sshpass 不起作用
- c# - 有什么方法可以使用 EF Core 在多台服务器上更新相同的 [database].[table]?