Heads up! To view this whole video, sign in with your Treehouse account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
In this tutorial video, Dustin will guide you through the process of building a ChatGPT-powered Discord bot. You'll learn how to create a bot that listens to messages in a designated channel, sends those messages to the ChatGPT API for processing, and then responds with the generated text from the AI. By the end of this tutorial, you'll have a functional Discord bot that can generate responses to user messages using the power of ChatGPT. So whether you're a seasoned developer or just starting out, come join Dustin and learn how to build a ChatGPT Discord bot today!
NPM packages to install:
npm i discord.js openai dotenv
Update
This workshop was recorded using v3 of the openai
package. The release of v4
introduced new initialization logic which might cause errors when following along with the workshop. You'll want to make the following adjustments compared to Dustins code:
Adjust the import:
// Old
import { Configuration, OpenAIApi } from "openai";
to be:
// New
import OpenAI from 'openai';
Then instead of using Configuration
and OpenAIApi
as shown you can initialize the OpenAI
class without separately creating the configuration.
// Old
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
// New
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY // This is also the default, can be omitted
});
If you're interested to find out what other changes were introduced you can check out the v3 to v4 Migration Guide
Resources
Discord
OpenAI
NodeJS
Additional Learning Content
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up