You want a Discord welcome bot that greets new members with a personalized image showing their username and a custom background. Standard text-only welcome messages lack visual impact and are easily overlooked in busy servers. A welcome bot that generates an image on the fly requires a bot account, a hosting environment, and a few Python libraries. This article explains how to build a Discord welcome bot using Python, the discord.py library, and Pillow for image generation.
The bot will listen for new members joining a server, then create a welcome image with the member’s name and server icon. The image is saved temporarily and uploaded to the welcome channel. You will need basic familiarity with Python, a Discord bot token, and a server where you have the Manage Server permission to invite the bot.
Key Takeaways: Build a Discord Welcome Bot With Image Generation
- discord.py library and discord.Intents: You must enable the Members intent in both the Discord Developer Portal and your bot code to receive new member events.
- Pillow (PIL) and io.BytesIO: Use Pillow to draw text and paste images, then save the result to a bytes buffer to avoid writing temporary files to disk.
- on_member_join event handler: The bot triggers image generation and sends the welcome image as a Discord file attachment inside this event.
How the Discord Welcome Bot Works
The welcome bot uses the on_member_join event from discord.py. When a new member joins any server where the bot is present, the event fires. The bot then runs a function that creates a background image, adds text with the member’s name, and optionally overlays the server’s icon. The final image is saved to a bytes buffer using Python’s io.BytesIO and sent as a discord.File to a designated welcome channel.
The image generation relies on Pillow, the Python Imaging Library fork. You will need to install it with pip install Pillow. The bot also requires the discord.py library version 2.0 or later, installed with pip install discord.py. For hosting, you can run the bot on your local machine, a Raspberry Pi, or a cloud platform like Replit, Heroku, or a VPS. The bot must be invited with the bot scope and the Send Messages and Attach Files permissions.
Prerequisites
Before writing code, prepare the following:
- A Discord application and bot token from the Discord Developer Portal
- Python 3.8 or later installed on your machine or host
- Discord server where you have the
Manage Serverpermission to invite bots - A background image file (e.g.,
welcome_bg.png) placed in the same folder as your bot script
Steps to Build the Welcome Bot
- Create a Discord Application and Bot
Go to the Discord Developer Portal and click New Application. Give it a name, then go to the Bot tab. Click Add Bot and confirm. Under the Privileged Gateway Intents section, enable Server Members Intent and Message Content Intent. Copy the bot token and save it securely. - Invite the Bot to Your Server
In the Developer Portal, go to OAuth2 > URL Generator. Select the bot scope. Under Bot Permissions, check Send Messages, Attach Files, and Read Message History. Copy the generated URL, open it in your browser, and select your server to invite the bot. - Install Required Python Libraries
Open a terminal or command prompt and run:pip install discord.py Pillow
If you are on Linux, you may also need to installpython3-pilorpython3-pillowvia your package manager. - Write the Bot Script
Create a new file namedwelcome_bot.py. Use the code below as a template. ReplaceYOUR_BOT_TOKENwith the actual token you copied earlier. Also replaceYOUR_WELCOME_CHANNEL_IDwith the ID of the channel where you want the welcome image to appear. To get a channel ID, enable Developer Mode in Discord (User Settings > Advanced > Developer Mode), right-click the channel, and select Copy ID.import discord
from discord.ext import commands
from PIL import Image, ImageDraw, ImageFont
import io
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix='!', intents=intents)
WELCOME_CHANNEL_ID = 123456789012345678 # Replace with your channel ID
BACKGROUND_PATH = 'welcome_bg.png'
@bot.event
async def on_ready():
print(f'{bot.user} has connected to Discord!')
@bot.event
async def on_member_join(member):
channel = bot.get_channel(WELCOME_CHANNEL_ID)
if channel is None:
return
# Open background image
bg = Image.open(BACKGROUND_PATH).convert('RGBA')
draw = ImageDraw.Draw(bg)
# Load a font (adjust path or use default)
try:
font = ImageFont.truetype('arial.ttf', 60)
except IOError:
font = ImageFont.load_default()
# Add welcome text
text = f'Welcome, {member.name}!'
text_bbox = draw.textbbox((0, 0), text, font=font)
text_width = text_bbox[2] - text_bbox[0]
text_height = text_bbox[3] - text_bbox[1]
x = (bg.width - text_width) // 2
y = bg.height - text_height - 50
draw.text((x, y), text, fill='white', font=font)
# Save to bytes buffer
with io.BytesIO() as image_binary:
bg.save(image_binary, 'PNG')
image_binary.seek(0)
await channel.send(file=discord.File(fp=image_binary, filename='welcome.png'))
bot.run('YOUR_BOT_TOKEN') - Run the Bot
In the terminal, navigate to the folder containingwelcome_bot.pyand your background image. Run:python welcome_bot.py
You should see a message likeBotName has connected to Discord!. Now test by having a new member join the server, or use the!joincommand if you added one. The bot should send the welcome image to the designated channel.
Common Issues and How to Avoid Them
Bot Does Not Respond to New Members
The most common cause is missing the Members intent. Verify that Server Members Intent is enabled in the Discord Developer Portal under your bot’s settings. Also confirm that you set intents.members = True in your script. Without this, the on_member_join event will never fire.
Welcome Image Shows a Blank or Broken Image
This usually happens when the background image file path is incorrect or the file is missing. Ensure welcome_bg.png is in the same directory as your script. If you use a different file name or path, update the BACKGROUND_PATH variable. Also check that the image is a valid PNG or JPEG file.
Text Appears Cut Off or Misaligned
The text position is calculated using the image dimensions. If your background image has an unusual aspect ratio, adjust the x and y calculations. You can also use textbbox to get the exact text size and center it properly. If the font file is not found, the bot falls back to the default Pillow font, which may be very small. Install a TrueType font like Arial or use a system font path that exists on your host.
Bot Crashes on Startup with Permission Errors
Make sure the bot token is correct and that you have not accidentally included extra spaces or quotes. If you are hosting on a platform like Replit, store the token as an environment variable instead of hardcoding it. Also verify that the bot has the Send Messages and Attach Files permissions in the server. You can check this by right-clicking the server, selecting Server Settings > Roles, and ensuring the bot’s role has those permissions.
Image Generation Methods: Pillow vs Canvas API vs External Service
| Item | Pillow (Local) | Canvas API (Node.js) | External Service (Imgflip) |
|---|---|---|---|
| Description | Python library for image processing | Node.js library for server-side image generation | Third-party API that generates images on demand |
| Language | Python | JavaScript / TypeScript | Any language with HTTP requests |
| Setup | Install with pip | Install with npm | Sign up for API key |
| Customization | Full control over text, fonts, layers | Full control, similar to HTML Canvas | Limited to templates |
| Latency | Low (runs on your host) | Low (runs on your host) | Medium (network request) |
| Cost | Free | Free | Free tier with watermark |
| Best for | Simple text overlays on static backgrounds | Complex graphics, animations | Quick prototypes without coding image logic |
Pillow is the simplest choice for a Python Discord bot. It requires no external network calls and gives you complete control over the output. If you prefer JavaScript, Canvas API offers similar flexibility. External services are faster to set up but limit your design options and add dependency on a third party.
Your new welcome bot will greet every member with a custom image that makes them feel recognized. After the bot is running, consider adding extra features like a random background from a folder, server-specific messages, or a command to preview the welcome image. For advanced customization, explore Pillow’s drawing functions to add shapes, gradients, or user avatars to the welcome card.