Adding ChatGPT to Your Discord Bot Is Easy @WornOffKeys
Adding ChatGPT to Your Discord Bot Is Easy  @WornOffKeys
Uploaded July 2023 | Updated September 2026, 1 week ago
Create a simple ChatGPT bot using Discord.JS v14 and the OpenAI API.
🧠 Learn website dashboards + bot monetization ➡ levelupyourbot.com
🔥 Source code download ➡ wornoffkeys.com/code?yt=HHtMPTnIm0M

🙋‍♂️ Need help? Ask in our Discord community:
wornoffkeys.com/discord

📺 Watch more Discord.JS videos here:
wornoffkeys.com/playlist/djs

💡 Request new video ideas here:
wornoffkeys.com/content-request

📺 Subsribe for new videos here:
youtube.com/@WornOffKeys?sub_confirmation=1

🔗 Regex for counting tokens:
gist.github.com/AlexzanderFlores/580a8b90ababdca81f4f84ad542264c3

------------------------------

In this video tutorial, we will learn how to create a ChatGPT bot using Discord.JS v14. We will start by logging into our OpenAI account and generating API keys. Then, we will set up our project by creating a .env file to store our Discord token and OpenAI API key.

Next, we will listen for new messages in our chatgpt channel and ensure that our bot doesn't respond to itself. We will fetch recent messages in the channel to provide context for the conversation.

To avoid exceeding the token limit set by OpenAI, we will count the tokens in our messages using a regex string. We will install the OpenAI package and create a file to handle API calls.

In our main index file, we will import the necessary files and create variables to hold messages, maximum tokens, and current tokens. We will process messages based on token count and role (bot or human).

Finally, we will call the OpenAI API and send the response to the user in Discord. We will also add a typing indicator to make the bot appear more realistic.

Watch this tutorial to learn how to create a ChatGPT bot using Discord.JS and OpenAI. Customize your bot further with buttons by checking out the next video.

------------------------------

🕒 Timestamps:
00:00 Introduction
00:31 Listening for messages from the "chatgpt" channel
01:35 Counting tokens
02:19 OpenAI Setup
03:23 Putting it all together
05:11 Replying in the channel
05:25 Making your bot type

#discordjs #discordbots #wornoffkeys

FTC Legal Disclaimer - Some links found in my video descriptions might be affiliate links, meaning I will make commission on sales you make through my link. This is at no extra cost to you and it helps support the channel so I can make more free YouTube videos.
Adding ChatGPT to Your Discord Bot Is EasyDiscord JS - Calling APIs (2020) [Episode #53]MongoDB in NodeJS - Primary Keys and Unique IDs (2020) [Episode #18]Discord JS Bot and API Ping/Latency Command (2020) [Episode #35]How to make a Discord bot - Discord JS v13 [Ep. 1]Discord.JS Basic Command Handler (2020) [Episode #3]60 Seconds of Useful Visual Studio Code Shortcuts PART 2 #ShortsDiscord.JS v13 - WOKCommands Introduction [Ep. 5]Discord.JS v13 - Give, Remove, and Has Role Command [Ep. 15]Configurable Spawn Point - Spigot Plugin Development (2022)Event listeners and sending messages - Minecraft Plugin Development Ep. 2 (2021)MongoDB in NodeJS - Deleting Data (2020) [Episode #6]
Worn Off Keys |

Adding ChatGPT to Your Discord Bot Is Easy

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER