Skip to content

Discord bot written in Golang that interacts with the ChatGPT API

License

Notifications You must be signed in to change notification settings

rayspock/go-chatgpt-discord

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Release Github All Releases

ChatGPT Discord Bot

Discord bot written in Golang that interacts with the ChatGPT API.

go-chatgpt-discord-slash-command-demo

go-chatgpt-discord-direct-message-demo

Table of Contents

Features

  • [Slash Command]
    • Use /chat command to send a message to the bot in public channels, and it will respond with a message generated by the ChatGPT API.
  • [Direct Message]
    • Send private messages to the bot, and it will respond with a message generated by the ChatGPT API. This is useful for users who want to interact with the bot without broadcasting their messages to the whole server.
    • The responses generated by ChatGPT are streamed in real time so that users can see the progress of the completion. This is particularly useful for chat applications in which the user doesn't have to wait for a long time to see the result.

Installation

To run this bot, please follow these steps:

  1. Go to the releases page and download the binary that matches your operating system. Extract the binary to a directory of your choice (such as ~/go-chatgpt-discord).

  2. In the same directory as the binary, create a copy of env.example and name it .env Fill in the appropriate credentials as directed.

  3. Obtain a new OpenAI API key by following the link here. Then, fill in OPENAI_API_KEY.

  4. Set up your Discord application and add a bot from the Discord Developer Portal:

    • Fill out DISCORD_BOT_TOKEN with your Discord bot token from the Bot settings page.
    • Copy your "Client ID" from the OAuth2 tab and fill in DISCORD_CLIENT_ID.
  5. Check that the installation worked: chmod +x go-chatgpt-discord && ./go-chatgpt-discord

  6. Run the bot by executing ./go-chatgpt-discord. A bot invitation URL will appear in the console. Copy and paste this URL into your web browser to add the bot to your server.

  7. Enable direct messages from other members of your server by going to the "Privacy Settings" page of your server and enabling "Allow direct messages from server members".

  8. You're all set! You can now use the bot in your server by typing /chat in any channel, or by sending a direct message to the bot.

Local Development

# build a go binary
$ make

# for local development
$ make run 

# run unit tests
$ make test

Contributing

Welcome any kind of contribution to this repository. If you have any suggestions or ideas for improving the code examples or best practices, please feel free to open an issue or submit a pull request.

License

Distributed under the MIT License. See LICENSE for more information.