Deploy this function on flows.network, and you will get a Discord bot that uses ChatGPT to respond to every question in your Discord DM.
- You will need to bring your own OpenAI API key. If you do not already have one, sign up here.
- You also need a bot token to access the Discord API. Please refer to How to create a Discord chat bot to save the Discord API Token and invite the bot to your server. You can see the bot is offline now. But don't worry! After you finish all the steps, the bot will be online.
- Create a bot from a template
- Add your ChatGPT API key
- Add the Discord bot token
![image](https://private-user-images.githubusercontent.com/45785633/257054820-f53553da-ccec-4fa3-ada3-851d7c3b4c5e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjMyOTgxMTAsIm5iZiI6MTcyMzI5NzgxMCwicGF0aCI6Ii80NTc4NTYzMy8yNTcwNTQ4MjAtZjUzNTUzZGEtY2NlYy00ZmEzLWFkYTMtODUxZDdjM2I0YzVlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODEwVDEzNTAxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFhMzRhMTQ3MWY0Njc1ZTc2MWRkYjcwYTBjMjcxOTcyNzU0YTk2NWQxMGY4Y2Y1YWU4MmYyMWRjYWQyODZlZGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.FJc-NUKcf0l0sKp7Ll5czAv8IGentK2cIrprTxc4X7E)
Here you can see three variables. You can customize the system_prompt
variable to prompt ChatGPT.
Click on the Create and Build button.
You will now set up Discord integration. Enter your Discord token here. Please refer to How to create a Discord chat bot.
![image](https://private-user-images.githubusercontent.com/45785633/257054978-e978d2fe-5666-4862-84c6-91a87a25e929.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjMyOTgxMTAsIm5iZiI6MTcyMzI5NzgxMCwicGF0aCI6Ii80NTc4NTYzMy8yNTcwNTQ5NzgtZTk3OGQyZmUtNTY2Ni00ODYyLTg0YzYtOTFhODdhMjVlOTI5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODEwVDEzNTAxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWY4MTI1YzMwZWFkY2EzMDdiNGU1ZTY3ZThlZTRhNzc2OWJmNDNkOTBmNjE2OTIxYWIzZGNmY2UwYWU1Mjg3N2MmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.RKGrIsQMS1aW6ZYY6P7o1iiBD-FNrJNvlHTfWOeVx9I)
Click on Continue.
You will now set up OpenAI integration. Click on Connect, and enter your key.
Close the tab and go back to the flow.network page once you are done. Click on Deploy button.
When the status of the flow is ready and running, you can go back to your Discord server and check out the status of the bot you just invited.
Now you can see the bot on the right online
contact list. DM the bot or @the bot in a channel, the bot will answer your questions.
If you want to build locally, make sure you have installed Rust and added wasm32-wasi
traget.
cargo build --target wasm32-wasi --release