Command Handler Issues
I would like to use my command handler to execute this code whenever someone types a message in a specific channel. This command iis NOT tied to a slash command, but instead listens for messages sent by users. I don't understand how to make the command handler work with code other than code using SlashCommandBuilder.
12 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.
I've tried removing the
.setName()
and .setDescription()
functions, but when I do, I'm given an error stating my command must have a name. I don't understand, because no one will ever need to read this "invisble" command. I guess it's treating it like a slash command but it's not. I just wanbt to store each of my commands in seperate files so my index.js does not get too crammed.
This is my index.js file, if it helps.
[email protected]
Node: v18.16.1Do you have an event handler? You’re only calling this run function once hopefully.
Yes, I have an event handler but I don’t think any of this code interacts with my events handler.
If you have a messageCreate event listener you should check if the message is in the desired channel and call run() if it is. Move the ‘command’ file out of your slash command folder so that you’re not trying to parse it as one.
Would I put it in my events folder?
It’s not an event either so it would error there with the event handler
Could I make my command folder a slashcommands folder and make a new folder for basic commands.
My OpenAI code isn’t really a command. I think a better word would be interaction or integration.
You wouldn’t be able you put it anywhere you would have a handler load it in and require it to have certain properties it doesn’t. I would import it in your messageCreate event and call run() when needed. And that also means run() would NOT be creating any event listeners.
But could I have it in a separate file from index.js? Right now I have it in a file named gpt3.5.js.
That’s my main concern and take away from all of this.
Yeah as long as you just import it from your messageCreate event it should be fine.
I got it!
Thank you, SpecialSauce!