【发布时间】:2021-07-02 07:08:35
【问题描述】:
我正在使用以下 python 代码和discord.py 来创建一个带有discord.Client 实例的不和谐机器人。我希望机器人能够在 on_message(message:discord.Message) 函数中更改其在公会上的头像和昵称,以匹配发送最新消息的用户。如果你知道 Not Quite Nitro 机器人,我想做一些类似的事情(只是改变机器人的外观以匹配公会成员)。化身改变奏效了,至少是第一次。然后,在我尝试对其进行测试的大多数情况下,它都会抛出以下异常:
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In avatar: You are changing your avatar too fast. Try again later.
我认为头像更改有某种冷却时间。有办法规避吗?
另外,昵称从未更改成功。我已经在公会上给了这个机器人一个昵称,以便有一些东西可以改变,以防它修复它。这是代码: 所有不一致的缩进都是stackoverflow和复制粘贴的结果,实际代码中并不存在
async def on_message(message):
if message.author==client.user:
return
#some irrelevant code removed here
async with message.channel.typing():
#the code omitted here is irrelevant and worked
#the below code is the problematic portion
try:
await message.delete()
asset = message.author.avatar_url_as()
avatarBytes = await asset.read()
await client.user.edit(nick=message.author.display_name)
try:
await client.user.edit(avatar=avatarBytes)
except discord.errors.HTTPException:
#this error is the avatar changing too fast error
pass
await message.channel.send(content=message.content,files=fileList)
except discord.errors.HTTPException:
await message.channel.send("Too many images to send")
#for reference, this except block only triggers when it would have to send more than 10 files at once
机器人有权删除消息和管理昵称。这里发生了什么? 提前致谢!
【问题讨论】:
标签: python python-3.x asynchronous discord.py