Zero6992 / chatGPT-discord-bot

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

Error when bot receives a /chat command: Username cannot contain "discord" #404

Closed konstantin-goldman closed 1 year ago

konstantin-goldman commented 1 year ago

Love this project, thanks for putting it together!

Just forked this repo, built and ran it. Everything seemed successful, I added a bot to my private server and the Bot connected successfully:

2023-05-17 15:52:58 INFO     discord.client logging in using static token
2023-05-17 15:52:59 INFO     discord.gateway Shard ID None has connected to Gateway (Session ID: 77dc471c84d5a729e7ddedba3d252900).
2023-05-17 15:53:01 INFO     src.aclient -> No Channel selected. Skip sending system prompt.
2023-05-17 15:53:01 INFO     src.bot -> KonBot#0877 is now running!

However, whenever I send a /chat command from my server, the command runs indefinitely and I get the following error in the logs:

2023-05-17 15:53:03 ERROR    discord.app_commands.tree Ignoring exception in command 'chat'
Traceback (most recent call last):
  File "/Users/kon/.pyenv/versions/3.10.0/lib/python3.10/site-packages/discord/app_commands/commands.py", line 842, in _do_call
    return await self._callback(interaction, **params)  # type: ignore
  File "/Users/kon/workplace/discordGpt/src/bot.py", line 35, in chat
    await client.enqueue_message(interaction, message)
  File "/Users/kon/workplace/discordGpt/src/aclient.py", line 92, in enqueue_message
    await message.response.defer(ephemeral=self.isPrivate) if self.is_replying_all == "False" else None
  File "/Users/kon/.pyenv/versions/3.10.0/lib/python3.10/site-packages/discord/interactions.py", line 638, in defer
    await adapter.create_interaction_response(
  File "/Users/kon/.pyenv/versions/3.10.0/lib/python3.10/site-packages/discord/webhook/async_.py", line 221, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In name: Username cannot contain "discord"

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

Traceback (most recent call last):
  File "/Users/kon/.pyenv/versions/3.10.0/lib/python3.10/site-packages/discord/app_commands/tree.py", line 1252, in _call
    await command._invoke_with_namespace(interaction, namespace)
  File "/Users/kon/.pyenv/versions/3.10.0/lib/python3.10/site-packages/discord/app_commands/commands.py", line 869, in _invoke_with_namespace
    return await self._do_call(interaction, transformed_values)
  File "/Users/kon/.pyenv/versions/3.10.0/lib/python3.10/site-packages/discord/app_commands/commands.py", line 860, in _do_call
    raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'chat' raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In name: Username cannot contain "discord"

Spent some time debugging it but I was not able to figure it out. I don't have any users named *discord* in the server, and the bot is named KonBot. I tried logging the various objects involved in this process (discord.Interaction) but did not see anything related to the username. Is this a known issue? Anyone seen it before?

konstantin-goldman commented 1 year ago

The root cause was my discord application name included "Discord" - surprised it let's me create such a name and then complains when we try to call the API. Oh well, sorry for the alarm. Hopefully this record will be useful for someone in the future.