by Lazy Sloth
Discord Welcome Bot
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}.'
Discord Welcome Bot
Created: | Last Updated:
Introduction to the Discord Welcome Bot Template
Welcome to the Discord Welcome Bot template! This bot is designed to greet new members of your Discord server with a unique poem, creating a warm and personalized welcome experience. This article will guide you through the steps to set up and use this template on the Lazy platform.
Before we dive into the setup process, please ensure you have the following:
- A Discord account with permissions to add bots to a server.
- The 'DISCORD_BOT_TOKEN' which is the token of your Discord bot.
- The 'WELCOME_CHANNEL_ID' which is the ID of the channel where the bot will send welcome messages.
Now, let's get started with setting up your Discord Welcome Bot!
Start with this Template
To begin, click on the "Start with this Template" button. This will initiate the template within the Lazy Builder interface, pre-populating the code for you.
Setting Environment Secrets
Next, you'll need to set up environment secrets for your bot to function correctly. These are not set in your operating system but within the Lazy Builder itself. Here's how to do it:
- Locate the Environment Secrets tab within the Lazy Builder.
- Set the 'DISCORD_BOT_TOKEN' with the token of your Discord bot.
- Set the 'WELCOME_CHANNEL_ID' with the ID of the channel where the bot will send welcome messages.
These secrets are crucial for your bot's operation, as they allow it to authenticate with Discord and know where to send the welcome messages.
Using the Test Button
Once you have set your environment secrets, it's time to test your bot. Click the Test button to begin the deployment of your app. The Lazy CLI will launch, and you will be prompted for any required user input at this stage.
After the deployment is successful, the Lazy platform will provide you with a dedicated server link. This link is where your bot will be active and can interact with your Discord server.
External Integrations
To integrate the bot into your Discord server, follow these steps:
- Go to the Discord Developer Portal and create a new application.
- Within the application settings, navigate to the 'Bot' section and add a new bot.
- Copy the bot token provided and set it as the 'DISCORD_BOT_TOKEN' in the Environment Secrets tab.
- Invite the bot to your Discord server using the OAuth2 URL generator in the Developer Portal, with the appropriate permissions.
Remember, the bot will only be able to send messages to the channel specified by the 'WELCOME_CHANNEL_ID' environment secret.
Conclusion
With these steps completed, your Discord Welcome Bot is now set up and ready to greet new members with a unique poem. Enjoy creating a friendly and engaging environment for your server's newcomers!
If you need further assistance or have any questions, please refer to the documentation provided with the code or reach out for support.
Technologies
![Discord](https://media.pocketgamer.biz/2021/5/110514/discord-new-logo-2021-r225x225.jpg)