by Lazy Sloth
Discord Join and Leave Bot
import discord
from discord.ext import commands
import os
intents = discord.Intents.all()
intents.members = True
bot = commands.Bot(command_prefix='!', intents=intents)
# Global variables to store channel IDs
welcome_channel_id = ''
leave_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(welcome_channel_id)
if channel:
await channel.send(f'Welcome {member.mention} to the server!')
Discord Join and Leave Bot
Created: | Last Updated:
Introduction to the Discord Join and Leave Bot Template
Welcome to the step-by-step guide on how to set up and use the Discord Join and Leave Bot using the Lazy platform. This bot is designed to send automated welcome messages to new members when they join a Discord server and farewell messages when they leave. This guide will walk you through the process of setting up the bot, from starting with the template to integrating it into your Discord server.
Clicking Start with this Template
To begin using this template, simply click on the "Start with this Template" button on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code manually.
Initial setup: Adding Environment Secrets
Before you can test and use the bot, you need to set up an environment secret within the Lazy Builder. This secret is the 'DISCORD_TOKEN', which is necessary for the bot to interact with your Discord server.
- Go to the Discord Developer Portal and create a new application.
- Inside the application, navigate to the "Bot" section and add a new bot.
- Copy the bot's token provided in this section.
- Back in the Lazy Builder, go to the Environment Secrets tab.
- Create a new secret with the key 'DISCORD_TOKEN' and paste the token you copied as the value.
With the 'DISCORD_TOKEN' set, your bot is now ready to be deployed.
Test: Pressing the Test Button
Once you have set up the environment secret, press the "Test" button on the Lazy platform. This will begin the deployment of the bot and launch the Lazy CLI. The bot will start running, and you will see a confirmation in the CLI that it is logged in and ready.
Entering Input: Filling in User Input
There is no additional user input required through the CLI for this template. All configurations can be done through Discord commands once the bot is running.
Using the App
After deploying the bot, you can use it directly within your Discord server. Here's how to set up the welcome and leave channels:
- Invite the bot to your Discord server using the OAuth2 URL generated in the Discord Developer Portal.
- In Discord, use the command
!set_welcome_channel #channel-name
to set the channel where welcome messages will be sent. - Similarly, use the command
!set_leave_channel #channel-name
to set the channel for leave messages.
Replace #channel-name
with the actual channel you want to use for each type of message. Once set, the bot will automatically send welcome and leave messages in the specified channels.
Integrating the App
No further external integration is required for this template. The bot will function within your Discord server, and you can manage its settings using the provided commands.
Remember to ensure that the bot has the necessary permissions in your Discord server to read and send messages in the channels you have designated for welcome and leave messages.
That's it! You now have a fully functional Discord Join and Leave Bot running in your server, thanks to the Lazy platform.