Discord Bot RPG game command issues

Question: I am creating a Discord Bot RPG game. When I test out the “!create” command, it says it doesn’t exist and Im not sure where the problem is.


import os, discord
from discord.ext import commands

from replit import db
from game import *

DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")

intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="!", intents = intents)

#Helper functions
def load_character(user_id):
  return Character(**db["characters"][str(user_id)])

MODE_COLOUR = {
  GameMode.BATTLE: 0xDC143C,
  GameMode.ADVENTURE: 0x005EB8,
  }
def status_embed(ctx,character):
  #Current mode
  if character.mode == GameMode.BATTLE:
    mode_text = f"Currently battling a {character.battling.name}."
  elif character.mode == GameMode.ADVENTURE:
    mode_text = "Currently adventuring."

  #Creates embed with description
  embed = discord.Embed(title=f"{character.name} status", description = mode_text, colour = MODE_COLOUR[character.mode])
  embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)

  #Stats field
  _, xp_needed = character.ready_to_level_up()

  embed.add_field(name="Stats", value=f"""
  **HP:** {character.hp}/{character.max_hp}
  **ATTACK!** {character.atttack}
  **DEFENSE:** {character.defense}
  **MANA:** {character.mana}
  **LEVEL:** {character.level}
  **XP:*5 {character.xp}/{character.xp+xp_needed}
  """, inline=True)

  #Inventory field
  inventory_text = f"Gold: {chatacter.gold}\n"
  if character.inventory:
    inventory_test += "\n".join(character.inventory)

  embed.add_field(name="Inventory", value=inventory_text, inline = True)

  return embed

@bot.event
async def on_ready():
  print(f"{bot.user} has connected to Discord")

bot.run(DISCORD_TOKEN)

#Commands
@bot.command(name="create", help="Create a character.")
async def create(ctx, name=None):
  #await bot.process_commands("create")
  user_id = ctx.message.author.id
  #if no name, use the author's
  if not name:
    name = ctx.message.author.name

  #creates characters dictionary if it doesn't exist
  if "characters" not in db.keys():
    db["characters"] = {}

  #only create a new character if user doesn't have one already
  if user_id not in db["characters"] or not db["characters"][user_id]:
    character = Character(**{
      "name": name,
      "hp": 16,
      "max_hp": 16,
      "attack": 2,
      "defense": 1,
      "mana": 0,
      "level": 1,
      "xp": 0,
      "gold": 0,
      "inventory": [],
      "mode": GameMode.ADVENTURE,
      "battling": None,
      "user_id": user_id
    })
    character.save_to_db()
    await ctx.message.reply(f"New level 1 character created: {name}. Enter '!status' to see your stats.")
  else:
    await ctx.message.reply("You have already created your character.")
  #bot.run()
  
@bot.command(name="status", help="Get information about your character.")
async def status(ctx):
  character = load_character(ctx.message.author.id)
  embed = status_embed(ctx, character)
  await ctx.message.reply(embed=embed)

Hi @EnderBox . Thank you for your post.

In order for the community to suggest ideas to help you solve your code issue it would be useful to share a link to your Repl.

Any error messages that you see appear when you attempt to run your code would also be useful to share here.

I had just forgotten to move the bot.run(DISCORD_TOKEN) to the bottom but thanks anyways

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.