两个代码都有相同的错误。 “'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.")
答案 0 :(得分:0)
它是 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
,那么每次调用命令时都创建一个新会话是个坏主意,您应该始终只打开一个会话来执行所有请求。< /p>