Skip to content

Instantly share code, notes, and snippets.

@ivangarzab
Created September 19, 2025 06:14
Show Gist options
  • Select an option

  • Save ivangarzab/252d4dca9107a5397d3dc7fc0aa40f68 to your computer and use it in GitHub Desktop.

Select an option

Save ivangarzab/252d4dca9107a5397d3dc7fc0aa40f68 to your computer and use it in GitHub Desktop.
Bare-bones Discord Bot python file
import os
import random
import discord
from discord.ext import commands
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
# Replace this with your actual channel ID where you want welcome messages
WELCOME_CHANNEL_ID = <insert your server channel ID>
# Get the bot token from environment variable
TOKEN = os.getenv("TOKEN")
if not TOKEN:
raise ValueError("TOKEN environment variable is not set. Make sure you have a .env file with TOKEN=your_bot_token")
# Set up bot with necessary intents
intents = discord.Intents.default()
intents.message_content = True # Needed to read message content
intents.members = True # Needed to detect new members joining
bot = commands.Bot(command_prefix='/', intents=intents)
@bot.event
async def on_ready():
print(f'Bot logged in as {bot.user}')
print('Ready to add reactions and welcome new members!')
@bot.event
async def on_message(message):
# Don't respond to the bot's own messages
if message.author == bot.user:
return
# Random chance to add a reaction to any message
if random.randint(1, 10) <= 3: # 30% chance
reactions = ['πŸ˜€', 'πŸ‘', '❀️', 'πŸ˜‚', 'πŸ‘€', 'πŸŽ‰', 'πŸ”₯', '✨']
reaction = random.choice(reactions)
await message.add_reaction(reaction)
print(f"Added reaction {reaction} to message from {message.author.name}")
# This line allows other commands to still work (if you add any later)
await bot.process_commands(message)
@bot.event
async def on_member_join(member):
"""Welcome new members to the server"""
print(f"{member.name} joined the server")
# Get the welcome channel
channel = bot.get_channel(WELCOME_CHANNEL_ID)
if channel:
welcome_messages = [
f"Welcome to the server, {member.mention}! πŸ‘‹",
f"Hey there {member.mention}! Great to have you here! πŸŽ‰",
f"Welcome aboard, {member.mention}! Hope you enjoy your stay! ✨",
f"Hello {member.mention}! Welcome to our community! 😊"
]
welcome_message = random.choice(welcome_messages)
await channel.send(welcome_message)
# Run the bot
if __name__ == "__main__":
bot.run(TOKEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment