Python 更新bot';从一个url下载头像
我正在使用discord.py,似乎无法用图像url更新机器人的化身。如果这是一条路径,那么它运行良好。因此,我想得到一些帮助,知道到底是什么错了,以及如何解决它。这是我的密码。谢谢Python 更新bot';从一个url下载头像,python,url,io,discord,discord.py,Python,Url,Io,Discord,Discord.py,我正在使用discord.py,似乎无法用图像url更新机器人的化身。如果这是一条路径,那么它运行良好。因此,我想得到一些帮助,知道到底是什么错了,以及如何解决它。这是我的密码。谢谢 @commands.command(aliases=["edit"], hidden=True) @commands.is_owner() async def edit_bot_pic(self, ctx, avatar_location): valid
@commands.command(aliases=["edit"], hidden=True)
@commands.is_owner()
async def edit_bot_pic(self, ctx, avatar_location):
valid = validators.url(avatar_location)
if valid:
async with aiohttp.ClientSession() as session:
async with session.get(avatar_location) as resp:
buffer = io.BytesIO(await resp.read())
await self.bot.user.edit(avatar=buffer)
else:
with open(avatar_location, "rb") as file:
avatar = file.read()
await self.bot.user.edit(avatar=avatar)
你就快到了,你需要传递一个文件而不是缓冲区来让它工作
buffer=io.BytesIO(wait resp.read())
file=discord.file(缓冲区)
等待self.bot.user.edit(化身=文件)
参考资料:-