如何修改Discord selfbot的Python命令使其发送Embed嵌入式消息
修改方案
你只需要调用discord.Embed类创建嵌入式消息对象,再把内容填充到Embed的对应字段中,最后调用ctx.send()时传入embed参数即可。
完整修改后代码(带自定义样式版)
@knife.command() async def howgay(ctx, member: discord.Member): await ctx.message.delete() # 先生成随机数值 gay_rate = random.randint(0, 101) # 初始化Embed对象,设置标题、配色 embed = discord.Embed( title = "🏳️🌈 Gay率检测结果", color = discord.Color.random() # 也可指定固定颜色,比如discord.Color.blue() ) # 填充检测结果到Embed内容区 embed.add_field( name = "检测结果", value = f"{member.mention} 是 {gay_rate}% gay", inline = False ) # 可选配置:显示被检测用户头像 embed.set_thumbnail(url = member.avatar.url if member.avatar else member.default_avatar.url) # 发送Embed消息 await ctx.send(embed = embed)
极简修改版(仅改输出为Embed无额外样式)
@knife.command() async def howgay(ctx, member:discord.Member): await ctx.message.delete() gay_rate = random.randint(0,101) embed = discord.Embed(description=f"{member.mention} is {gay_rate}% gay") await ctx.send(embed=embed)
注意事项
- 如果你使用的是discord.py v2.0以下的旧版本,需要把
member.avatar.url替换为member.avatar_url才能正常显示用户头像 - Embed还支持自定义页脚、作者信息等字段,可根据需求自行扩展对应属性
内容的提问来源于stack exchange,提问作者oliverhunt204
相关产品推荐
相关产品推荐

