Created
September 19, 2025 06:14
-
-
Save ivangarzab/252d4dca9107a5397d3dc7fc0aa40f68 to your computer and use it in GitHub Desktop.
Bare-bones Discord Bot python file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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