Discord Custom Welcome Message Bot

By
 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}.'

About this template

This welcome message bot will be designed to perform a single task on Discord, which is to welcome new users with a unique poem. The welcome message can be customized to any other aesthetic ideas and greetings. This cutom bot requires two environment variables to function properly: DISCORD_BOT_TOKEN (the token of your Discord bot) and WELCOME_CHANNEL_ID (the ID of the channel where the bot will send welcome messages).

Introduction to the Discord Custom Welcome Message Bot Template

Welcome to the step-by-step guide on how to use the Discord Custom Welcome Message Bot template on the Lazy platform. This template is designed to help you create a bot that welcomes new members to your Discord server with a unique poem. The bot is easy to set up and requires no coding experience. By following this guide, you'll be able to deploy your own welcome bot in no time.

Clicking Start with this Template

To begin, click on the "Start with this Template" button. This will initialize the template within the Lazy Builder interface, pre-populating the code necessary for your welcome message bot.

Initial Setup: Adding Environment Secrets

Before you can test your bot, you need to set up two environment secrets that the bot requires to function:

  • DISCORD_BOT_TOKEN: The token for your Discord bot, which allows it to interact with the Discord API.
  • WELCOME_CHANNEL_ID: The ID of the Discord channel where the bot will send welcome messages.

To acquire these, you'll need to create a bot on the Discord Developer Portal and invite it to your server. Here are the steps:

  1. Go to the Discord Developer Portal and create a new application.
  2. Within the application, navigate to the "Bot" tab and click "Add Bot".
  3. Under the bot settings, you'll find the token. Click "Copy" to get your DISCORD_BOT_TOKEN.
  4. Invite the bot to your server by using the OAuth2 URL generator in the "OAuth2" tab, selecting the appropriate permissions.
  5. Once the bot is in your server, right-click on the channel you want to use for welcome messages and click "Copy ID" to get your WELCOME_CHANNEL_ID.

After obtaining these values, enter them into the Environment Secrets tab within the Lazy Builder.

Test: Pressing the Test Button

With the environment secrets set, you can now press the "Test" button. This will deploy your application and launch the Lazy CLI. The CLI will prompt you for any required user input.

Entering Input: Filling in User Input

Analyze the code to see if the code requires user input through the CLI. If the code does not prompt for user input, you can omit this section.

Using the App

If the app hosts a frontend experience, this section will guide you through interacting with it. However, since this template is for a Discord bot, there is no frontend interface to discuss.

Integrating the App

Once your bot is running, it will automatically send a welcome poem to new members who join your Discord server. If you need to change the welcome channel, use the provided command within your Discord server:


!set_welcome_channel #channel-name

Replace "#channel-name" with the actual channel you wish to set as the new welcome channel.

That's all there is to it! Your Discord Custom Welcome Message Bot is now set up and ready to greet new members with a poetic touch. Enjoy engaging your community with this unique and personal touch.

Category
Technology
Last published
April 7, 2024

More templates like this

WhatsApp ChatBot (Twilio, InstantChat)

Build a WhatApp chatbot using Twilio, Discord and LazyAI.

WhatsApp
Twilio
Discord

GreetingBot

GreetingBot: A discord bot that welcomes new members to your server.

Discord

Stock AI Advice

The bot requires certain permissions to function properly. These include the ability to read message history, send messages, and react to messages. The bot will generate stats such as This bot will provide ticker stats, commodity stats, Stock News and other AI Stock Trading Advice Please provide the Discord bot token in the Env Secrets tab under the name 'DISCORD_BOT_TOKEN' and your API Key for the Alpha Advantage

Discord
Python
Home
/
Discord Custom Welcome Message Bot