mail@pastecode.io avatar
7 months ago
5.2 kB

import discord
from discord.ext import commands
import os
import embed
import webserver


prefix = "?"  # your bot prefix between quotes
client = commands.Bot(command_prefix=prefix, intents=discord.Intents.all())

# Remove the default help command

async def on_ready():
    await client.change_presence(status=discord.Status.idle, activity=discord.Activity(type=discord.ActivityType.listening, name="?help"))
    print(f"We have logged in as {client.user.name}")

async def on_message(message):
    if not message.author.bot:
        if message.content.lower().startswith("?"):
            await client.process_commands(message)
            response = await chatgpt_api_call(message.content)
            if response:
                await message.channel.send(f"```python\n{response}\n```")

async def chatgpt_api_call(message):
    # You can add your ChatGPT API integration here
    # Implement your logic to generate code using ChatGPT

async def hello(ctx):
    Greets the user with a hello message.
    hello_embed = embed.hello_embed()
    await ctx.send(embed=hello_embed)

async def kick(ctx, member: discord.Member, *, reason=None):
    Kicks a member from the server.
    Usage: ?kick [member] [reason]
    kick_embed = embed.kick_embed()
    await member.kick(reason=reason)
    await ctx.send(embed=kick_embed)

async def purge(ctx, amount=5):
    Deletes a specified number of messages.
    Usage: ?purge [amount]
    purge_embed = embed.purge_embed(amount)
    # Delete the command message
    await ctx.message.delete()

    # Delete the specified number of messages (up to 100)
    deleted = await ctx.channel.purge(limit=amount)

    # Send a message indicating how many messages were deleted
    message = await ctx.send(embed=purge_embed)
    await message.delete(delay=5)

async def snipe(ctx):
    Retrieves the last deleted message in the channel.
    # Check if the channel has a deleted message to snipe
    if ctx.channel.id not in sniped_messages:
        await ctx.send("There's nothing to snipe!")

    # Retrieve the last deleted message for the channel
    message = sniped_messages[ctx.channel.id]

    # Send the sniped message to the channel
    snipe_embed = embed.snipe_embed(message)
    await ctx.send(embed=snipe_embed)

async def ban(ctx, member: discord.Member, *, reason=None):
    Bans a member from the server.
    Usage: ?ban [member] [reason]
    ban_embed = embed.ban_embed(member)
    await member.ban(reason=reason)
    await ctx.send(embed=ban_embed)

async def warn(ctx, member: discord.Member, reason: str = None):
    Warns a member in the server.
    Usage: ?warn [member] [reason]
    warn_embed = embed.warn_embed(member, reason)
    await ctx.send(embed=warn_embed)
        await member.send(embed=warn_embed)

@client.command(aliases=["calc", "c"])
async def calculate(ctx, *args):
    Evaluates a mathematical expression.
    Usage: ?calculate [expression]
        ans = eval(' '.join(args))
        calculate_embed = embed.calculate_embed(ans)
        await ctx.send(embed=calculate_embed)
        calculate_error_embed = embed.calculate_error_embed(ctx.author)
        await ctx.send(embed=calculate_error_embed)

async def help(ctx, command_name=None):
    if command_name:
        # Get the specified command object
        command = client.get_command(command_name)
        if command:
            # Send the command's description as an embed
            command_embed = embed.command_help_embed(command.name, command.help)
            await ctx.send(embed=command_embed)
            await ctx.send("Command not found.")
        # Send the general help message with a list of commands and descriptions
        commands = {
            "ban": "Bans a member from the server.",
            "calculate": "Evaluates a mathematical expression.",
            "hello": "Greets the user with a hello message.",
            "kick": "Kicks a member from the server.",
            "purge": "Deletes a specified number of messages.",
            "snipe": "Retrieves the last deleted message in the channel.",
            "warn": "Warns a member in the server."
            # Add more commands and descriptions here...
        help_embed = embed.help_embed(commands)
        await ctx.send(embed=help_embed)

# Create a dictionary to store the last deleted message in each channel
sniped_messages = {}

async def on_message_delete(message):
    # Store the last deleted message for each channel in the sniped_messages dictionary
    sniped_messages[message.channel.id] = message

TOKEN = os.getenv("DISCORD_TOKEN") or os.environ["DISCORD_TOKEN"]