在Discord中更改机器人的化身

2024-05-13 10:04:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在用户运行命令时替换机器人的化身图像。我该怎么做?我成功地替换了昵称,但没有替换图像

await ctx.guild.me.edit(nick=nick)

^替换昵称

我试过(尼克=尼克,阿凡达=阿凡达),但没有成功

编辑:

@client.command()
async def test(ctx):
    if ctx.guild.id == second_server:
        await ctx.guild.me.edit(nick=nick, avatar_url=avatar)
        pfp_path = "Profile-Picture.png"
        with open(pfp_path, "rb") as pfp:
            await client.user.edit(password=None, avatar=pfp.read())
            print("profile picture changed")

Tags: path用户图像命令client机器人awaitedit
1条回答
网友
1楼 · 发布于 2024-05-13 10:04:15

根据official docs的意见,应采取以下措施:

import discord
  
client = discord.Client()

token = '...'

@client.event
async def on_ready():
    pfp_path = "file.jpg"
    with open(pfp_path, "rb") as pfp:
        await client.user.edit(password=None, avatar=pfp.read())
    print("profile picture changed")

client.run(token)

您不能直接提供所需配置文件图片的URL

注意:仅支持JPEG和PNG格式

相关问题 更多 >