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

Discord.py开发:如何在一行发送多张角色图片

Fixing Inline Character Images for Your Discord.py Team Bot

Hey there! Great job getting your team-building bot up and running—random team recommendations with character art sounds awesome. Let's get those three images to display in a single line instead of stacking vertically.

Here are a couple of straightforward solutions depending on how you're currently serving your character images:

1. For Hosted/Online Images (Easiest Fix)

If your character images are hosted online (like a personal server or image hosting platform), you can combine all three image markdown tags into a single line and send them in one message. Discord will render them side-by-side as long as the image dimensions aren't excessively large.

Before (Possible Original Code)

# Sends each image in a separate line/message
for character in recommended_team:
    await ctx.send(f"![{character.name}]({character.image_url})")

After (Fixed Code)

# Combine all image tags into one line
inline_images = " ".join([f"![{character.name}]({character.image_url})" for character in recommended_team])
await ctx.send(content=inline_images)

2. Using Discord Embeds (More Polished Layout)

If you want to wrap the team in a clean, styled embed with a title or description, use inline fields to place each image side-by-side:

import discord

# Create an embed for the team recommendation
team_embed = discord.Embed(title="🔍 Your Random Team", description="Here's your 3-person squad!")

# Add each character as an inline field
for index, character in enumerate(recommended_team, start=1):
    team_embed.add_field(
        name=f"Character {index}",
        value=f"![{character.name}]({character.image_url})",
        inline=True  # This forces fields to sit side-by-side
    )

await ctx.send(embed=team_embed)

3. For Local Character Images

If you're using local image files instead of hosted URLs, attach all files to the same message and reference them with attachment links:

# Prepare files and image references
attached_files = []
image_references = []

for idx, character in enumerate(recommended_team):
    # Create a File object for each local image
    img_file = discord.File(character.local_image_path, filename=f"char_{idx}.png")
    attached_files.append(img_file)
    # Reference the attached file in markdown
    image_references.append(f"![{character.name}](attachment://char_{idx}.png)")

# Send all files and the combined image line
await ctx.send(content=" ".join(image_references), files=attached_files)

Quick Tip

If your images are extra wide, Discord might still stack them—try resizing them to a consistent, smaller width (like 200-300px) to ensure they fit neatly side-by-side.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 14:47:54