You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

discord.py发送带玻璃滤镜头像的Embed显示空白如何解决

问题修复方案

核心问题说明

  • 参数逻辑错误:声明了接收被@成员的person参数,但实际取头像时用的是指令触发者ctx.message.author的头像,完全没有用到被@对象的信息;同时没有处理用户未@任何成员的默认场景,重复的类型注解person: discord.Member无实际作用。
  • 头像URL格式异常:discord.py返回的avatar_url是Asset对象,直接拼接进API地址时部分第三方接口无法正常识别,需要显式转为字符串格式。
  • 缺少必要依赖导入:代码中使用的discord、commands类未声明导入,同时导入的aiohttp、json、requests在当前逻辑中无用途可以移除。

修正后代码

import discord
from discord.ext import commands

# 注意需要根据实际需求开启对应网关意图,成员识别需要开启Server Members Intent
bot = commands.Bot(command_prefix=']', intents=discord.Intents.all())

# glass filter
@bot.command()
async def glass(ctx, *, person: discord.Member = None):
    # 未@人时默认使用指令触发者的头像
    if not person:
        person = ctx.author
    embed = discord.Embed()
    # 显式将头像Asset对象转为字符串URL,保证API可正常识别
    avatar_url = str(person.avatar_url)
    embed.set_image(url=f'https://some-random-api.ml/canvas/glass?avatar={avatar_url}')
    await ctx.send(embed=embed)

额外注意事项

  • 需在Discord开发者后台的机器人设置页开启Server Members Intent权限,否则无法正常识别被@的成员对象
  • 确保机器人在对应服务器拥有发送Embed消息的权限,避免消息被拦截

内容的提问来源于stack exchange,提问作者Rovindu Thamuditha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 08:45:04