kingcrickets

create a bot that says "heyyyyy" to everyone who joins

Kodari AI
KodariAug 17 at 5:17 pm 1
HeyGreeter
A Discord bot that automatically sends a friendly "heyyyyy" message to every new member who joins a server. The bot listens for member join events using discord.py's on_member_join event handler, then posts the greeting in the server's system channel or a designated welcome channel. Includes simple setup with a bot token, and optionally supports customizing the greeting message via environment variables or config. Perfect for making new members feel welcomed instantly.

Created a Discord bot that:

  • Sends heyyyyy when a member joins

  • Uses the server’s system channel, with a writable text-channel fallback

  • Loads DISCORD_TOKEN from environment variables

  • Enables the required members intent

  • Includes dependency and .env template files

Run it with:

Shell
pip install -r requirements.txt
cp .env.example .env
python bot.py

Enable Server Members Intent in the Discord Developer Portal.

Kodari can make mistakes. Review important code before using.
Files
bot.py
requirements.txt
Code
2 47
bot.py
import logging
import os

import discord
from dotenv import load_dotenv


load_dotenv()

logging.basicConfig(level=logging.INFO)

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

client = discord.Client(intents=intents)


@client.event
async def on_ready() -> None:
    logging.info("Logged in as %s", client.user)


@client.event
async def on_member_join(member: discord.Member) -> None:
    channel = member.guild.system_channel

    if channel is None:
        channel = next(
            (
                text_channel
                for text_channel in member.guild.text_channels
                if text_channel.permissions_for(member.guild.me).send_messages
            ),
            None,
        )

    if channel is not None:
        await channel.send("heyyyyy")


token = os.getenv("DISCORD_TOKEN")
if not token:
    raise RuntimeError("DISCORD_TOKEN is not set in the environment")

client.run(token)