【问题标题】:I need to change a python discord bot's avatar (profile picture) using discord.py rewrite我需要使用 discord.py rewrite 更改 python discord bot 的头像(个人资料图片)
【发布时间】:2021-01-26 21:42:31
【问题描述】:

这是我目前用于更改头像的代码:

with open("image.png", "rb") as file:
     await discord.ClientUser.edit(self=, avatar=file)

首先,我什至不知道这是否是您更改机器人头像的方式。如果是这样的话,我不知道我需要在self= 之后放什么。我尝试阅读文档并询问人们如何做到这一点,但我没有找到任何解决这个问题的方法。任何帮助将不胜感激。

这就是我定义我的客户的方式:client = commands.Bot(command_prefix='.')

【问题讨论】:

  • 这个命令在 cog 文件中吗?
  • @Nurqm 不,它在一个 .py 文件中,其中包含机器人的其余代码。

标签: python discord bots discord.py discord.py-rewrite


【解决方案1】:

上面的答案有正确的想法,但缺少一些东西。

这是怎么做的:

with open('image.png', 'rb') as image:
    await client.user.edit(avatar=image.read())

【讨论】:

    【解决方案2】:

    您可以使用ClientUser 更改头像,但您需要致电班级。你不能做discord.ClientUser.edit。要更改头像,您需要bytes like object。所以,这应该工作:

    with open('image.png', 'rb') as image:
        await client.user.edit(avatar=image)
    

    【讨论】:

    • 我收到此错误:AttributeError: 'Bot' object has no attribute 'edit'
    • 你能用你定义client的代码行来编辑你的问题吗?还有,你的命令前缀是什么?
    • 我已经尝试过使用client.user.edit.(avatar=...)。它给了我这个错误:AttributeError: '_io.BufferedReader' object has no attribute 'startswith'
    • 使用client.edit(avatar=image) 给我这个错误AttributeError: 'Bot' object has no attribute 'edit' 和这个错误discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Bot' object has no attribute 'edit'
    • Nvm 我忘了我需要打电话给班级。我会去做的
    猜你喜欢
    • 2021-08-13
    • 2020-02-23
    • 1970-01-01
    • 2019-04-29
    • 2018-08-25
    • 2015-04-01
    • 2021-09-23
    • 2018-01-16
    • 2014-08-31
    相关资源
    最近更新 更多