Files
.gitignore
main.py
README.md
requirements.txt
Code
4 152
main.py
import discord
import os
import re
import asyncio
from dotenv import load_dotenv
load_dotenv()
client = discord.Client()
# Configuration
POKETWO_BOT_ID = 716390085896962058 # Official Pokétwo bot ID
CATCH_COMMAND_PREFIX = "<@716390085896962058> c" # @Pokétwo c
DELAY_SECONDS = 0.5 # Delay before catching (to avoid spam detection)
@client.event
async def on_ready():
print(f'Self-bot is ready! Logged in as {client.user}')
print(f'Monitoring for Pokémon spawns...')
@client.event
async def on_message(message):
# Ignore our own messages
if message.author.id == client.user.id:
return
# Check if message is from Pokétwo bot
if message.author.id != POKETWO_BOT_ID:
return
# Check if message contains embeds (Pokémon spawns usually have embeds)
if message.embeds:
embed = message.embeds[0]
# Check if it's a spawn message (usually contains "wild pokémon" or similar)
if embed.title and "wild" in embed.title.lower():
# Try to extract Pokémon name from embed description or title
pokemon_name = extract_pokemon_name(embed)
if pokemon_name:
print(f'Detected spawn: {pokemon_name}')
await asyncio.sleep(DELAY_SECONDS)
await message.channel.send(f'{CATCH_COMMAND_PREFIX} {pokemon_name}')
print(f'Sent catch command for: {pokemon_name}')
# Also check plain text messages (if spawn format is different)
if message.content:
# Look for pattern like "Doduo :_:" or similar
pokemon_name = extract_from_text(message.content)
if pokemon_name:
print(f'Detected spawn in text: {pokemon_name}')
await asyncio.sleep(DELAY_SECONDS)
await message.channel.send(f'{CATCH_COMMAND_PREFIX} {pokemon_name}')
print(f'Sent catch command for: {pokemon_name}')
def extract_pokemon_name(embed):
"""Extract Pokémon name from embed"""
# Try from description first
if embed.description:
# Pattern: "Doduo :_:" or "A wild Doduo appeared!"
match = re.search(r'(\w+)\s*:_:', embed.description)
if match:
return match.group(1).lower()
match = re.search(r'wild\s+(\w+)', embed.description, re.IGNORECASE)
if match:
return match.group(1).lower()
# Try from title
if embed.title:
match = re.search(r'wild\s+(\w+)', embed.title, re.IGNORECASE)
if match:
return match.group(1).lower()
return None
def extract_from_text(text):
"""Extract Pokémon name from plain text message"""
# Pattern: "Doduo :_:" or similar formats
match = re.search(r'(\w+)\s*:_:', text)
if match:
return match.group(1).lower()
# Pattern: "A wild Doduo appeared!"
match = re.search(r'wild\s+(\w+)', text, re.IGNORECASE)
if match:
return match.group(1).lower()
return None
# Run the self-bot
client.run(os.getenv('DISCORD_TOKEN'), bot=False)