#๐Ÿ”’ Text based RPG: "load_character" for status command

13 messages ยท Page 1 of 1 (latest)

hasty forge
#

Hi, i am new to python and i wanted to build a bot for discord to make a text based rpg. I got to the point where i can "create" a character but the "status" command has a problem, which i don'T understand.

The following is the error message i get:

Traceback (most recent call last):
  File "/home/runner/workspace/.pythonlibs/lib/python3.11/site-packages/discord/ext/commands/core.py", line 235, in wrapped
    ret = await coro(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/workspace/main.py", line 57, in status
    character = load_character(ctx.message.author.id)
                ^^^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'load_character' where it is not associated with a value

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/runner/workspace/.pythonlibs/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 1366, in invoke
    await ctx.command.invoke(ctx)
  File "/home/runner/workspace/.pythonlibs/lib/python3.11/site-packages/discord/ext/commands/core.py", line 1029, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/workspace/.pythonlibs/lib/python3.11/site-packages/discord/ext/commands/core.py", line 244, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: UnboundLocalError: cannot access local variable 'load_character' where it is not associated with a value```

Since i just started with coding in general i don't really know what the problem is. Tried asking ai but that also i didn't understand.
So pls. If one of you know what ia have to do, pls help.
fringe foxBOT
#

@hasty forge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

ripe kayak
hasty forge
#

okey and uhm how do i fix that?

ripe kayak
#

Did you define it as a variable somewhere?

#

Is it supposed to be a function?

hasty forge
#

yes

#

i did

#

its supposed to load the status, like hp, mp, etc of the character

ripe kayak
hasty forge
#

i am confused...one sec...

fringe foxBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.