Discord Custom Welcome Message Bot

Customize this app
50
import os
import discord
from discord.ext import commands
from abilities import llm_prompt

intents = discord.Intents.all()
intents.members = True

bot = commands.Bot(command_prefix='!', intents=intents)

# Global variable to store channel ID
welcome_channel_id = os.getenv('WELCOME_CHANNEL_ID')

@bot.event
async def on_ready():
    print(f'Logged in as {bot.user.name}')

@bot.event
async def on_member_join(member):
    if welcome_channel_id:
        channel = bot.get_channel(int(welcome_channel_id))
        if channel:
            # Generate a unique poem for the new member
            poem_prompt = f'Write a short welcome poem for a new member named {member.name}.'
Get full code

Discord Custom Welcome Message Bot

Created: | Last Updated:

Here's a step-by-step guide on how to use the Discord Custom Welcome Message Bot template:

Introduction

This template provides a Discord bot that welcomes new members to your server with a unique, AI-generated poem. The bot uses the GPT-4 model to create personalized welcome messages for each new member.

Getting Started

  1. Click "Start with this Template" to begin using the Discord Custom Welcome Message Bot template in Lazy.

Initial Setup

Before testing the bot, you need to set up two environment secrets:

  1. DISCORD_BOT_TOKEN: This is your Discord bot's token.
  2. WELCOME_CHANNEL_ID: This is the ID of the channel where welcome messages will be sent.

To set up these environment secrets:

  1. Go to the Discord Developer Portal (https://discord.com/developers/applications).
  2. Create a new application or select an existing one.
  3. Navigate to the "Bot" section and create a bot if you haven't already.
  4. Copy the bot token.
  5. In the Lazy Builder, go to the Environment Secrets tab.
  6. Add a new secret named DISCORD_BOT_TOKEN and paste your bot token as the value.
  7. To get the WELCOME_CHANNEL_ID:
  8. Enable Developer Mode in Discord (User Settings > Advanced > Developer Mode).
  9. Right-click on the channel you want to use for welcome messages and select "Copy ID".
  10. In the Lazy Builder, add another secret named WELCOME_CHANNEL_ID and paste the channel ID as the value.

Test

Click the "Test" button to deploy and run your Discord bot.

Using the App

Once the bot is running:

  1. Invite the bot to your Discord server using the OAuth2 URL generated in the Discord Developer Portal.
  2. The bot will automatically send a welcome message with a unique poem when a new member joins the server.
  3. To change the welcome channel, use the command !set_welcome_channel #channel-name in your Discord server.

Integrating the App

To fully integrate this bot into your Discord server:

  1. Ensure the bot has the necessary permissions:
  2. In the Discord Developer Portal, go to the "OAuth2" section.
  3. Under "Scopes", select "bot".
  4. Under "Bot Permissions", select:
    • Read Messages/View Channels
    • Send Messages
    • Manage Messages (optional, for better message control)
  5. Generate the invite link and use it to add the bot to your server.
  6. Once the bot is in your server, it will automatically start welcoming new members.

Remember to keep your bot token secret and never share it publicly. With these steps completed, your Discord Custom Welcome Message Bot should be fully operational and ready to greet new members with unique poems!

Technologies

Discord Discord
Python Python