ChatGPT Forum
GPT + Discord Bot - Printable Version

+- ChatGPT Forum (https://gptforum.org)
+-- Forum: Usage & Applications (https://gptforum.org/forumdisplay.php?fid=15)
+--- Forum: Tutorials (https://gptforum.org/forumdisplay.php?fid=39)
+--- Thread: GPT + Discord Bot (/showthread.php?tid=13)



GPT + Discord Bot - Admin - 09-24-2025

Want to add GPT directly to your Discord server? Here’s a simple bot setup.

Requirements:
  • Discord developer account + bot token
  • Python with discord.py and openai

Example Code:
Code:
import discord
from openai import OpenAI

client = OpenAI(api_key="YOUR_API_KEY")
bot = discord.Client(intents=discord.Intents.default())

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return

    if message.content.startswith("!gpt"):
        prompt = message.content[4:].strip()
        response = client.chat.completions.create(
            model="gpt-4",
            messages=[{"role": "user", "content": prompt}]
        )
        await message.channel.send(response.choices[0].message["content"])

bot.run("DISCORD_BOT_TOKEN")