So, everyone is going stir-crazy over these AI Agents like ChatGPT, Google Gemini, and Claude. I figured as a project and learning experience. I would write a Discord bot in Python and use webhooks to allow it to talk to my n8n deployment to interact with ChatGPT and respond to the Discord channel
Well, I have successfully done it, but it's not perfect. The main issue is, depending on what you ask it. ChatGPT will respond with a large swath of text and Discord limits you to 2,000 characters (4,000 if you have Nitro upgrade)
When this happens, the Discord node that talks to the Discord webhook just fails when it tries to send responses that are larger than the current limit. I suspect I can just have ChatGPT respond to a Python or JavaScript code which can divide the response up into multiple messages. Though I haven't went through that process yet.
The current process is I created a text chatroom in Discord called Oracle. I created a Python Discord bot that joins the server and monitors that channel. It ignores any messages that aren't directed at the bot.
ie: "@OracleBot [Question for ChatGPT]" (mine is not named OracleBot, but I digress)
The bot then takes that message and strips of his name and trims the text then sends that message to my n8n server where I have a workflow that accepts messages from a webhook.
That webhook forwards the message to an AI Agent which has ChatGPT (and some other tools that accesses data that I have) connected to it to resolve questions.
Once the question has been resolved, the AI Agent sends the response to a Discord node that then sends the response directly to the channel where the questions was asked.
Here is a flowchat of the happenings:
![]() |
n8n flow for a Discord ChatGPT Bot |
At some point, I will provide my Python Discord bot, but it's a hack job at this point and I want to clean it up and possibly add some nice features to it. Once I do that, I can update this post with that code.
No comments:
Post a Comment