#[Discord Bot] Application Commands Not working & Bot Stuck On Starting

1 messages · Page 1 of 1 (latest)

compact hawk
#
from discord.ext import commands
import json
import os

# Replace with your actual bot token and guild ID
GUILD_ID =   # Replace with your actual guild/server ID
PET_DATA_FILE = 'pets.json'

intents = discord.Intents.default()
bot = commands.Bot(command_prefix='?', intents=intents)

# Load pet data from JSON file
def load_pet_data():
    if os.path.exists(PET_DATA_FILE):
        with open(PET_DATA_FILE, 'r') as file:
            return json.load(file)
    return {}

# Save pet data to JSON file
def save_pet_data(data):
    with open(PET_DATA_FILE, 'w') as file:
        json.dump(data, file, indent=4)

# Register commands
@bot.event
async def on_ready():
    print(f'Logged in as {bot.user}')
    commands = await bot.tree.sync(guild=discord.Object(id=GUILD_ID))
    print(f"Synced {len(commands)} commands.")  # Print the number of synced commands
    print('Successfully completed startup')


@bot.tree.command(name="add", description="Add a new pet")
async def add_pet(interaction: discord.Interaction, fr: int, nfr: int, mfr: int, name: str, link: str):
    # Command implementation

    pets = load_pet_data()
    if name in pets:
        await interaction.response.send_message(f"Pet with name {name} already exists!", ephemeral=True)
        return
    
    pets[name] = {
        "name": name,
        "link": link,
        "fr": f"Cash: ${fr} / Robux: R${fr * 40}",
        "nfr": f"Cash: ${nfr} / Robux: R${nfr * 40}",
        "mfr": f"Cash: ${mfr} / Robux: R${mfr * 40}"
    }
    save_pet_data(pets)
    await interaction.response.send_message(f"Pet {name} added successfully!")

@bot.tree.command(name="edit", description="Edit an existing pet")
async def edit_pet(interaction: discord.Interaction, fr: int, nfr: int, mfr: int, name: str, link: str):
    pets = load_pet_data()
    if name not in pets:
        await interaction.response.send_message(f"No pet found with name {name}!", ephemeral=True)
        return
    
    pets[name]["link"] = link
    pets[name]["fr"] = f"Cash: ${fr} / Robux: R${fr * 40}"
    pets[name]["nfr"] = f"Cash: ${nfr} / Robux: R${nfr * 40}"
    pets[name]["mfr"] = f"Cash: ${mfr} / Robux: R${mfr * 40}"
    save_pet_data(pets)
    await interaction.response.send_message(f"Pet {name} updated successfully!")

@bot.tree.command(name="remove", description="Remove a pet")
async def remove_pet(interaction: discord.Interaction, name: str):
    pets = load_pet_data()
    if name not in pets:
        await interaction.response.send_message(f"No pet found with name {name}!", ephemeral=True)
        return
    
    del pets[name]
    save_pet_data(pets)
    await interaction.response.send_message(f"Pet {name} removed successfully!")

@bot.tree.command(name="pet", description="Get details of a pet")
async def pet(interaction: discord.Interaction, name: str):
    pets = load_pet_data()
    if name not in pets:
        await interaction.response.send_message(f"No pet found with name {name}!", ephemeral=True)
        return

    pet_info = pets[name]
    embed = discord.Embed(title=pet_info["name"], description="Pet details")
    embed.set_thumbnail(url=pet_info["link"])
    embed.add_field(name="FR", value=pet_info["fr"], inline=True)
    embed.add_field(name="NFR", value=pet_info["nfr"], inline=True)
    embed.add_field(name="MFR", value=pet_info["mfr"], inline=True)
    embed.set_footer(text="Made by MQGH")
    
    await interaction.response.send_message(embed=embed)

# Run the bot
    print('Successfully completed startup')  # Added confirmation of startup
TOKEN = ''
bot.run('')```
#

This is the current code of the bot. Can anyone help it maybe be rewritten or something?
This is how it works, but I want the pets to be able to show up as '?owl'
I removed the token and guild ID
Add Pets:

The bot allows users to add new pets using a slash command (/add).
The command takes several parameters:
fr: Price in cash/robux for the FR (Fly Ride) variant.
nfr: Price for the NFR (Not Fly Ride) variant.
mfr: Price for the MFR (Mega Fly Ride) variant.
name: The name of the pet.
link: A URL link to an image of the pet.
Edit Pets:

The bot provides a way to edit existing pets using a command that allows users to change details like price and image link.
Remove Pets:

Users can remove pets from the list through a specific command.
Display Pets:

The bot retrieves pet information from a JSON file (pets.json) and displays it in a structured embed format when users call the pet's name as a command (e.g., /owl).
The embed includes:
Title: Pet Name
Footer: "Made by MQGH"
Thumbnail: Image link
Prices for FR, NFR, and MFR variants formatted with cash and Robux.
Data Storage:

All pet data is stored in a JSON file, making it easy to manage and retrieve information.
Example of Bot Interactions
Adding a Pet:

Command: /add fr: 10 nfr: 5 mfr: 15 name: Owl link:
The bot responds with a confirmation message that the pet has been added.
Editing a Pet:

Command: /edit name: Owl fr: 12 nfr: 6 mfr: 18 link:
The bot updates the pet's information.
Removing a Pet:

Command: /remove name: Owl
The bot removes the pet and confirms the action.
Displaying Pet Information:

Command: /owl
The bot shows an embed with the Owl's details, including pricing in cash and Robux

willow grotto
#

[Discord Bot] Application Commands Not working & Bot Stuck On Starting

compact hawk
#

When I type /add, no prompt is showing up either

thorn sparrow
#

Ah wait that’s in your on_ready. Please don’t do that

haughty coral