Untitled

 avatar
unknown
plain_text
2 years ago
5.2 kB
6
Indexable

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

webserver.keep_alive()

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

# Remove the default help command
client.remove_command("help")

@client.event
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}")

@client.event
async def on_message(message):
    if not message.author.bot:
        if message.content.lower().startswith("?"):
            await client.process_commands(message)
        else:
            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

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

@client.command()
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)

@client.command()
@commands.has_permissions(manage_messages=True)
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)

@client.command()
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!")
        return

    # 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)

@client.command()
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)

@client.command()
@commands.has_permissions(kick_members=True)
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)
    try:
        await member.send(embed=warn_embed)
    except:
        pass

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

@client.command()
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)
        else:
            await ctx.send("Command not found.")
    else:
        # 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 = {}

@client.event
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"]
client.run(TOKEN)
Editor is loading...