Skip to main content

๐ŸŒ™ Luna-Py - Ultimate All-in-One Python Library for Discord Bots

Project description

๐ŸŒ™ Luna-Py - Ultimate All-in-One Python Library

PyPI version Python version License Discord.py

Luna-Py is the ultimate all-in-one Python library for Discord bots! Easy Discord bot creation, webhooks, HTTP client, TrueWallet API, and utilities - all in one package! ๐Ÿ๐Ÿš€

โœจ Features

  • ๐Ÿค– Discord Bot - Easy bot creation with discord.py
  • ๐Ÿ“จ Discord Webhooks - Simple webhook management
  • ๐ŸŽจ Embeds & Buttons - Beautiful message components
  • ๐ŸŒ HTTP Client - Powerful HTTP requests with auto-retry
  • ๐Ÿ’ฐ TrueWallet API - Voucher redemption
  • ๐Ÿ› ๏ธ Utilities - Useful helper functions
  • ๐Ÿ” Crypto - Encoding and token generation

๐Ÿ“ฆ Installation

pip install luna-py

Requirements:

  • Python 3.8+
  • discord.py 2.3+

๐Ÿš€ Quick Start

Basic Discord Bot

import luna

# Create bot
bot = luna.LunaBot.create_bot(command_prefix="!")

@bot.command()
async def ping(ctx):
    await ctx.reply("๐Ÿ“ Pong!")

@bot.command()
async def hello(ctx):
    await bot.luna_reply_embed(
        ctx,
        title="๐Ÿ‘‹ Hello!",
        description=f"Hi {ctx.author.mention}!",
        color=luna.LunaEmbed.BLUE
    )

bot.run("YOUR_BOT_TOKEN")

Bot with Embed

import luna

bot = luna.LunaBot.create_bot()

@bot.command()
async def info(ctx):
    embed = luna.LunaEmbed.create(
        title="๐Ÿ“Š Server Info",
        description="Information about this server",
        color=luna.LunaEmbed.DISCORD,
        fields=[
            {"name": "๐Ÿ‘ฅ Members", "value": str(ctx.guild.member_count), "inline": True},
            {"name": "๐Ÿ“… Created", "value": ctx.guild.created_at.strftime("%Y-%m-%d"), "inline": True}
        ],
        thumbnail=str(ctx.guild.icon.url) if ctx.guild.icon else None,
        footer="Powered by Luna-Py",
        timestamp=True
    )
    await ctx.reply(embed=embed)

bot.run("YOUR_BOT_TOKEN")

Bot with Buttons

import luna
import discord

bot = luna.LunaBot.create_bot()

@bot.command()
async def menu(ctx):
    embed = luna.LunaEmbed.create(
        title="๐ŸŽฎ Game Menu",
        description="Choose an option:",
        color=luna.LunaEmbed.BLUE
    )
    
    # Create buttons
    button1 = luna.LunaButton.create(
        label="Play Game",
        custom_id="play",
        style=discord.ButtonStyle.success,
        emoji="๐ŸŽฎ"
    )
    
    button2 = luna.LunaButton.create(
        label="Rules",
        custom_id="rules",
        style=discord.ButtonStyle.primary,
        emoji="๐Ÿ“œ"
    )
    
    # Create view with buttons
    view = luna.LunaView(button1, button2)
    
    await ctx.reply(embed=embed, view=view)

# Handle button clicks
@bot.event
async def on_interaction(interaction):
    if interaction.type == discord.InteractionType.component:
        if interaction.data['custom_id'] == 'play':
            await interaction.response.send_message("๐ŸŽฎ Starting game...")
        elif interaction.data['custom_id'] == 'rules':
            await interaction.response.send_message("๐Ÿ“œ Here are the rules...")

bot.run("YOUR_BOT_TOKEN")

๐Ÿ“– Complete Examples

Welcome Bot

import luna

bot = luna.LunaBot.create_bot()

@bot.event
async def on_member_join(member):
    channel = discord.utils.get(member.guild.channels, name="welcome")
    if not channel:
        return
    
    embed = luna.LunaEmbed.create(
        title="๐Ÿ‘‹ Welcome!",
        description=f"Welcome to the server, {member.mention}!",
        color=luna.LunaEmbed.GREEN,
        thumbnail=str(member.avatar.url) if member.avatar else None,
        fields=[
            {"name": "๐Ÿ“Š Member Count", "value": str(member.guild.member_count), "inline": True},
            {"name": "๐Ÿ“… Account Created", "value": member.created_at.strftime("%Y-%m-%d"), "inline": True}
        ],
        footer="Enjoy your stay!",
        timestamp=True
    )
    
    await channel.send(embed=embed)

@bot.event
async def on_ready():
    print(f"โœ… {bot.user} is ready!")

bot.run("YOUR_BOT_TOKEN")

TrueWallet Bot

import luna

bot = luna.LunaBot.create_bot()

@bot.command()
async def redeem(ctx, voucher_link: str, phone: str):
    """Redeem TrueWallet voucher"""
    await ctx.reply("โณ Redeeming voucher...")
    
    result = luna.LunaTrueWallet.redeem_voucher(voucher_link, phone)
    
    if result.get("status", {}).get("code") == "SUCCESS":
        embed = luna.LunaEmbed.create(
            title="โœ… Voucher Redeemed!",
            description=result["status"]["message"],
            color=luna.LunaEmbed.SUCCESS,
            fields=[
                {"name": "๐Ÿ’ฐ Amount", "value": f"{result['data']['amount']} THB", "inline": True},
                {"name": "๐Ÿ“ฑ Phone", "value": phone, "inline": True}
            ],
            timestamp=True
        )
    else:
        embed = luna.LunaEmbed.create(
            title="โŒ Redeem Failed",
            description=result.get("status", {}).get("message", "Unknown error"),
            color=luna.LunaEmbed.ERROR,
            timestamp=True
        )
    
    await ctx.reply(embed=embed)

bot.run("YOUR_BOT_TOKEN")

Shop Bot

import luna
import discord

bot = luna.LunaBot.create_bot()

# Product catalog
products = [
    {"id": "prod1", "name": "๐ŸŽฎ Robux 100", "price": 50},
    {"id": "prod2", "name": "๐Ÿ’Ž Diamonds 500", "price": 100},
    {"id": "prod3", "name": "โญ Premium", "price": 150},
]

@bot.command()
async def shop(ctx):
    """Display shop"""
    fields = [
        {"name": p["name"], "value": f"Price: {p['price']} THB", "inline": True}
        for p in products
    ]
    
    embed = luna.LunaEmbed.create(
        title="๐Ÿ›๏ธ Shop",
        description="Choose a product to buy:",
        color=luna.LunaEmbed.BLUE,
        fields=fields
    )
    
    # Create buy buttons
    buttons = [
        luna.LunaButton.create(
            label=p["name"],
            custom_id=f"buy_{p['id']}",
            style=discord.ButtonStyle.success
        )
        for p in products
    ]
    
    view = luna.LunaView(*buttons)
    await ctx.reply(embed=embed, view=view)

@bot.event
async def on_interaction(interaction):
    if interaction.type == discord.InteractionType.component:
        custom_id = interaction.data['custom_id']
        
        if custom_id.startswith('buy_'):
            product_id = custom_id.replace('buy_', '')
            product = next((p for p in products if p['id'] == product_id), None)
            
            if product:
                embed = luna.LunaEmbed.create(
                    title="โœ… Purchase Successful!",
                    description=f"You bought: {product['name']}",
                    color=luna.LunaEmbed.SUCCESS,
                    fields=[
                        {"name": "๐Ÿ’ฐ Price", "value": f"{product['price']} THB"}
                    ]
                )
                await interaction.response.send_message(embed=embed, ephemeral=True)

bot.run("YOUR_BOT_TOKEN")

๐ŸŽจ Discord Embeds

Create Embeds

import luna

embed = luna.LunaEmbed.create(
    title="๐ŸŽ‰ Announcement",
    description="This is an important announcement!",
    color=luna.LunaEmbed.DISCORD,
    url="https://example.com",
    author={"name": "Admin Team", "icon_url": "https://example.com/icon.png"},
    fields=[
        {"name": "Category", "value": "Updates", "inline": True},
        {"name": "Priority", "value": "High", "inline": True}
    ],
    thumbnail="https://example.com/thumb.png",
    image="https://example.com/image.png",
    footer="Announcement System",
    timestamp=True
)

# Send embed
await channel.send(embed=embed)

Available Colors

luna.LunaEmbed.RED        # 0xFF0000
luna.LunaEmbed.GREEN      # 0x00FF00
luna.LunaEmbed.BLUE       # 0x0000FF
luna.LunaEmbed.YELLOW     # 0xFFFF00
luna.LunaEmbed.PURPLE     # 0x800080
luna.LunaEmbed.ORANGE     # 0xFFA500
luna.LunaEmbed.DISCORD    # 0x5865F2
luna.LunaEmbed.SUCCESS    # 0x00FF00
luna.LunaEmbed.ERROR      # 0xFF0000
luna.LunaEmbed.WARNING    # 0xFFFF00
luna.LunaEmbed.INFO       # 0x0099FF

๐Ÿ“จ Discord Webhooks

import luna

# Send simple message
luna.LunaWebhook.send(
    webhook_url="YOUR_WEBHOOK_URL",
    content="Hello from Luna-Py! ๐Ÿ",
    username="My Bot",
    avatar_url="https://example.com/avatar.png"
)

# Send embed
embed = luna.LunaEmbed.create(
    title="Webhook Message",
    description="Sent via webhook!",
    color=luna.LunaEmbed.BLUE
)

luna.LunaWebhook.send_embed(
    webhook_url="YOUR_WEBHOOK_URL",
    embed=embed
)

๐ŸŒ HTTP Client

import luna

# Create HTTP client
http = luna.LunaHTTP(timeout=30, max_retries=3)

# GET request
response = http.get("https://api.example.com/data")
print(response.json())

# POST request
response = http.post(
    "https://api.example.com/users",
    json={"name": "John", "email": "john@example.com"}
)

๐Ÿ’ฐ TrueWallet API

import luna

result = luna.LunaTrueWallet.redeem_voucher(
    voucher_link="https://gift.truemoney.com/campaign/?v=xxxxx",
    phone_number="0812345678"
)

if result.get("status", {}).get("code") == "SUCCESS":
    print(f"โœ… Received {result['data']['amount']} THB")
else:
    print(f"โŒ Error: {result.get('status', {}).get('message')}")

๐Ÿ› ๏ธ Utilities

import luna

# Sleep
luna.LunaUtils.sleep(1)  # Sleep 1 second

# Async sleep
await luna.LunaUtils.async_sleep(1)

# Random
num = luna.LunaUtils.random(1, 100)  # Random number 1-100
text = luna.LunaUtils.random_string(16)  # Random string

# Format
formatted = luna.LunaUtils.format_number(1234567)  # "1,234,567"
date = luna.LunaUtils.format_date()  # "2024-11-23 14:30:00"

# List operations
chunks = luna.LunaUtils.chunk_list([1,2,3,4,5,6], 2)  # [[1,2], [3,4], [5,6]]

# Timestamp
ts = luna.LunaUtils.timestamp()  # Unix timestamp

๐Ÿ” Crypto

import luna

# Base64 encoding
encoded = luna.LunaCrypto.base64_encode("Hello World")
decoded = luna.LunaCrypto.base64_decode(encoded)

# Generate token
token = luna.LunaCrypto.generate_token(32)  # 64-char hex token

๐Ÿ“‹ API Reference

Discord Bot

  • LunaBot.create_bot(command_prefix, intents) - Create bot
  • LunaBot.create_client(intents) - Create client
  • LunaEmbed.create(**kwargs) - Create embed
  • LunaButton.create(**kwargs) - Create button
  • LunaView(*buttons, timeout) - Create view

Webhooks

  • LunaWebhook.send(webhook_url, **kwargs) - Send message
  • LunaWebhook.send_embed(webhook_url, embed, **kwargs) - Send embed

HTTP

  • LunaHTTP(timeout, max_retries) - Create client
  • http.get(url, **kwargs) - GET request
  • http.post(url, **kwargs) - POST request
  • http.put(url, **kwargs) - PUT request
  • http.delete(url, **kwargs) - DELETE request

TrueWallet

  • LunaTrueWallet.redeem_voucher(link, phone) - Redeem voucher

Utils

  • LunaUtils.sleep(seconds) - Sleep
  • LunaUtils.async_sleep(seconds) - Async sleep
  • LunaUtils.random(min, max) - Random number
  • LunaUtils.random_string(length) - Random string
  • LunaUtils.format_number(num) - Format number
  • LunaUtils.chunk_list(lst, size) - Chunk list
  • LunaUtils.timestamp() - Unix timestamp
  • LunaUtils.format_date(dt, format) - Format date

Crypto

  • LunaCrypto.base64_encode(text) - Encode base64
  • LunaCrypto.base64_decode(encoded) - Decode base64
  • LunaCrypto.generate_token(length) - Generate token

๐Ÿ’ก Getting Your Bot Token

  1. Go to https://discord.com/developers/applications
  2. Create "New Application"
  3. Go to "Bot" section
  4. Click "Reset Token" and copy it
  5. Enable necessary intents
  6. Invite bot to your server

๐Ÿ“ฆ Dependencies

  • discord.py >= 2.3.0
  • requests >= 2.31.0
  • aiohttp >= 3.9.0

๐Ÿค Contributing

Contributions welcome! Open issues or PRs on GitHub.


๐Ÿ“„ License

MIT ยฉ Luna-Py Team


๐Ÿ”— Links


Made with ๐ŸŒ™ by Luna Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lunahub_py-1.0.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lunahub_py-1.0.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file lunahub_py-1.0.0.tar.gz.

File metadata

  • Download URL: lunahub_py-1.0.0.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for lunahub_py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f1af800c903257c75c41f91a7d5628c67842282eeb278544eb14869a1041f4a7
MD5 dfff5575c8435d4bf01b7a4fc87ec6f8
BLAKE2b-256 2b75b860efc20e3bdb98e9dc4338a8ad31cdf8298d00d2b51cbc4cad48a3928f

See more details on using hashes here.

File details

Details for the file lunahub_py-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: lunahub_py-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for lunahub_py-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ae05564eabeaba4076bf73638bde0efa6079018c82575296b7c12d920321e10
MD5 e46f70678750e894c18f74afd3da94b2
BLAKE2b-256 5803c2ff196b91fa7668307a6569c516461a9d9087a6eb5dab7278c2680e89a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page