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

Python Discord申请机器人嵌入消息显示完整问题求助

Discord机器人Embed消息修改方案

实现步骤

1. 定位发送Embed的代码

先找到机器人里负责向指定频道发送提交通知的代码块,原代码大概是这样的:

# 原发送通知的代码示例
embed = discord.Embed(title="新申请提交", color=discord.Color.blue())
embed.add_field(name="问题编号", value=question_id, inline=False)
embed.add_field(name="答案", value=answer_content, inline=False)
await target_channel.send(embed=embed)

2. 确认完整问题的获取路径

确保你的代码已经从提交的申请数据(比如用户填写的模态框、表单或数据库)中拿到了完整的问题文本,假设这个内容存储在full_question变量里。

3. 修改Embed添加问题内容

在原Embed结构里新增一个字段来展示完整问题,修改后的代码如下:

# 修改后的发送代码
embed = discord.Embed(title="新申请提交", color=discord.Color.blue())
embed.add_field(name="问题编号", value=question_id, inline=False)
# 新增完整问题展示字段
embed.add_field(name="完整问题", value=full_question, inline=False)
embed.add_field(name="提交答案", value=answer_content, inline=False)
# 可选:添加时间戳让消息更直观
embed.timestamp = datetime.datetime.utcnow()
await target_channel.send(embed=embed)

4. 兼容长文本场景

Discord的Embed单字段最多支持1024字符,如果问题内容过长,可做截断处理或把问题放到Embed的描述区:

# 长文本兼容方案
# 自动截断超过1000字符的内容,避免报错
desc = f"**完整问题:**\n{full_question[:1000]}..." if len(full_question) > 1000 else f"**完整问题:**\n{full_question}"
embed = discord.Embed(title="新申请提交", description=desc, color=discord.Color.blue())
embed.add_field(name="问题编号", value=question_id, inline=False)
embed.add_field(name="提交答案", value=answer_content, inline=False)
await target_channel.send(embed=embed)

注意事项

  • 要确保full_question变量确实存储了完整的问题内容,避免出现空值或截断内容
  • 测试不同长度的问题,验证Embed在Discord中的显示效果,防止因字符超限导致发送失败
  • 如果是从用户交互组件(如模态框)获取问题,需确认代码正确接收了用户输入的全部内容

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 15:26:00