Zero6992 / chatGPT-discord-bot

Integrate ChatGPT into your own discord bot
GNU General Public License v2.0
2.63k stars 701 forks source link

ImportError: cannot import name 'AppCommandOptionType' from 'discord.enums' #40

Closed Omupp closed 1 year ago

Omupp commented 1 year ago

When I run it, I get the following error and it does not work

File "/opt/chatgpt/main.py", line 1, in <module> from src import bot File "/opt/chatgpt/src/bot.py", line 2, in <module> from discord import app_commands File "/usr/local/lib/python3.10/dist-packages/discord/app_commands/__init__.py", line 12, in <module> from .commands import * File "/usr/local/lib/python3.10/dist-packages/discord/app_commands/commands.py", line 51, in <module> from ..enums import AppCommandOptionType, AppCommandType, ChannelType, Locale ImportError: cannot import name 'AppCommandOptionType' from 'discord.enums' (/root/.local/lib/python3.10/site-packages/discord/enums.py)

Zero6992 commented 1 year ago

What's your python version?

Omupp commented 1 year ago

Version is 3.10.6

Zero6992 commented 1 year ago

You did pip install -r requirements.txt?

Omupp commented 1 year ago

yes

Zero6992 commented 1 year ago

Help me check out your discord.py version

pip show discord

Omupp commented 1 year ago

Version: 2.1.0

Zero6992 commented 1 year ago

Version: 2.1.0

I have updated the latest version and you can try, removing from discord import app_commands in bot.py as it is not being used

Omupp commented 1 year ago

The first error went away, but the next error appeared

File "/opt/chatgpt2/main.py", line 4, in <module> bot.run_discord_bot() File "/opt/chatgpt2/src/bot.py", line 83, in run_discord_bot @client.tree.command(name="chat", description="Have a chat with ChatGPT") AttributeError: 'Bot' object has no attribute 'tree'

Zero6992 commented 1 year ago

The first error went away, but the next error appeared

File "/opt/chatgpt2/main.py", line 4, in <module> bot.run_discord_bot() File "/opt/chatgpt2/src/bot.py", line 83, in run_discord_bot @client.tree.command(name="chat", description="Have a chat with ChatGPT") AttributeError: 'Bot' object has no attribute 'tree'

I'm having a bit of difficulty reproducing this error locally

I tried 3.10.6 and didn't have any issues

Could you tell me your environment? And I will continue tracking on it

Omupp commented 1 year ago

Ubuntu 22.04.1 Connected via remote desktop, for some reason I had to type Python3 instead of Python to run it, run as root user

Omupp commented 1 year ago

"python main.py" is not executable "python3 main.py" is executable

Zero6992 commented 1 year ago

I see

Omupp commented 1 year ago

Sorry! Maybe I did not communicate it properly! In my environment, if I use Python instead of Python3, I cannot run the program itself, so the error is based on the assumption that Python3 is used.

Omupp commented 1 year ago

After initialization and downgrading to Ubuntu 20.04, these errors are gone.

CMOSfail commented 1 year ago

Hi, I seem to get this error as well, and I can't resolve it on my own:

Traceback (most recent call last):
  File "D:\Projects\PythonProjects\Bots\chatGPT-discord-bot\main.py", line 1, in <module>
    from src import bot
  File "D:\Projects\PythonProjects\Bots\chatGPT-discord-bot\src\bot.py", line 6, in <module>
    from src.aclient import client
  File "D:\Projects\PythonProjects\Bots\chatGPT-discord-bot\src\aclient.py", line 7, in <module>
    from discord import app_commands
  File "C:\Program Files\Python311\Lib\site-packages\discord\app_commands\__init__.py", line 12, in <module>
    from .commands import *
  File "C:\Program Files\Python311\Lib\site-packages\discord\app_commands\commands.py", line 50, in <module>
    from ..enums import AppCommandOptionType, AppCommandType, ChannelType, Locale
ImportError: cannot import name 'AppCommandOptionType' from 'discord.enums' (C:\Users\thebl\AppData\Roaming\Python\Python311\site-packages\discord\enums.py)

Any suggestions?

Thanks

CMOSfail commented 1 year ago

Hi, I seem to get this error as well, and I can't resolve it on my own:

Traceback (most recent call last):
  File "D:\Projects\PythonProjects\Bots\chatGPT-discord-bot\main.py", line 1, in <module>
    from src import bot
  File "D:\Projects\PythonProjects\Bots\chatGPT-discord-bot\src\bot.py", line 6, in <module>
    from src.aclient import client
  File "D:\Projects\PythonProjects\Bots\chatGPT-discord-bot\src\aclient.py", line 7, in <module>
    from discord import app_commands
  File "C:\Program Files\Python311\Lib\site-packages\discord\app_commands\__init__.py", line 12, in <module>
    from .commands import *
  File "C:\Program Files\Python311\Lib\site-packages\discord\app_commands\commands.py", line 50, in <module>
    from ..enums import AppCommandOptionType, AppCommandType, ChannelType, Locale
ImportError: cannot import name 'AppCommandOptionType' from 'discord.enums' (C:\Users\thebl\AppData\Roaming\Python\Python311\site-packages\discord\enums.py)

Any suggestions?

Thanks

Also, these are the versions of stuff:

discord.py==2.2.2 python-dotenv==1.0.0 asgiref==3.6.0 openai==0.27.6 revChatGPT==5.0.2 GoogleBard==1.0.2 EdgeGPT==0.4.2 selenium==4.9.1 undetected-chromedriver==3.4.7

Python 3.11.3 (Also tried 3.9 with no luck)

Working on a Windows 11 x64 machine