Skip to content
This repository was archived by the owner on May 18, 2024. It is now read-only.

Bot won't respond to DM #231

Closed
nyxshadow2629 opened this issue Oct 2, 2023 · 3 comments
Closed

Bot won't respond to DM #231

nyxshadow2629 opened this issue Oct 2, 2023 · 3 comments

Comments

@nyxshadow2629
Copy link

I have chacked every setting I can find to try get the bot to DM back, will only react to messages. I have both my discord token and chimera gpt key inputted in as required. This is what error message I am getting back.

Traceback (most recent call last):
File "/home/runner/Discord-AI-Chatbot/.pythonlibs/lib/python3.10/site-packages/discord/client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "/home/runner/Discord-AI-Chatbot/main.py", line 173, in on_message
response = await asyncio.to_thread(generate_response, instructions=instructions, search=search_results, history=history)
File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/asyncio/threads.py", line 25, in to_thread
return await loop.run_in_executor(None, func_call)
File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/runner/Discord-AI-Chatbot/bot_utilities/ai_utils.py", line 92, in generate_response
response = openai.ChatCompletion.create(
File "/home/runner/Discord-AI-Chatbot/.pythonlibs/lib/python3.10/site-packages/openai/api_resources/chat_completion.py", line 25, in create
return super().create(*args, **kwargs)
File "/home/runner/Discord-AI-Chatbot/.pythonlibs/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 151, in create
) = cls.__prepare_create_request(
File "/home/runner/Discord-AI-Chatbot/.pythonlibs/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 108, in __prepare_create_request
requestor = api_requestor.APIRequestor(
File "/home/runner/Discord-AI-Chatbot/.pythonlibs/lib/python3.10/site-packages/openai/api_requestor.py", line 139, in init
self.api_key = key or util.default_api_key()
File "/home/runner/Discord-AI-Chatbot/.pythonlibs/lib/python3.10/site-packages/openai/util.py", line 186, in default_api_key
raise openai.error.AuthenticationError(
openai.error.AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = ', or you can set the environment variable OPENAI_API_KEY=). If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = '. You can generate API keys in the OpenAI web interface. See https://platform.openai.com/account/api-keys for details.

@skzhengkai
Copy link

Hi there,

I understand you're facing an issue with the bot not being able to DM back and only reacting to messages. The error message you posted indicates that the OpenAI API key is not being recognized. Here are some advanced debugging steps and code modifications you can try:

Debugging Steps:

  1. Check Environment Variables: Make sure that the OpenAI API key is correctly set as an environment variable if that's how you're configuring it.
  2. Check Code for API Key: Verify that the code is correctly reading the API key from the environment variables or from a config file.
  3. Check for Typos: Ensure that there are no typos in the variable names or the API key itself.
  4. Check File Permissions: Make sure that the file or environment variable where the API key is stored is accessible by the Python script.
  5. Check API Key Validity: Make sure that the API key is valid and has the necessary permissions.

Code Modifications:

  1. Explicitly Set API Key in Code: As a last resort, you can explicitly set the API key in your code to see if that resolves the issue. However, this is not recommended for production use due to security reasons.
    import openai
    openai.api_key = "your_openai_api_key_here"
  2. Advanced Logging: Add advanced logging to trace the flow of the API key within your application.
    import logging
    logging.basicConfig(level=logging.DEBUG)
    logger = logging.getLogger(__name__)
    try:
        # Your OpenAI API call here
    except Exception as e:
        logger.debug(f"API Key used: {openai.api_key}")
        logger.exception("Exception occurred", exc_info=True)
  3. Exception Handling: Add more robust exception handling to catch and log errors.
    try:
        # Your OpenAI API call here
    except openai.error.AuthenticationError as auth_error:
        logger.error(f"Authentication Error: {auth_error}")
    except Exception as general_error:
        logger.error(f"An unexpected error occurred: {general_error}")

By following these advanced debugging steps and implementing the code modifications, you should be able to resolve the issue you're facing. If the problem persists, please provide more details for further investigation.

Best,
Adam

@mishl-dev
Copy link
Owner

Chatgpt wrote that lol

@mishl-dev
Copy link
Owner

Stale

@mishl-dev mishl-dev closed this as not planned Won't fix, can't repro, duplicate, stale Oct 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants