Error on interactionCreate
This code keeps giving this error "TypeError: interaction.isChatInputCommand is not a function
at Object.execute (C:\Users\btrah\OneDrive\Desktop\Stuff for Others\k-link\events\interactionCreate.js:6:20)
at Client.<anonymous> (C:\Users\btrah\OneDrive\Desktop\Stuff for Others\k-link\index.js:47:48)
at Client.emit (node:events:508:28)
at InteractionCreateAction.handle (C:\Users\btrah\OneDrive\Desktop\Stuff for Others\k-link\node_modules\discord.js\src\client\actions\InteractionCreate.js:101:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\btrah\OneDrive\Desktop\Stuff for Others\k-link\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\btrah\OneDrive\Desktop\Stuff for Others\k-link\node_modules\discord.js\src\client\websocket\WebSocketManager.js:352:31)
at WebSocketManager.<anonymous> (C:\Users\btrah\OneDrive\Desktop\Stuff for Others\k-link\node_modules\discord.js\src\client\websocket\WebSocketManager.js:236:12)
at WebSocketManager.emit (C:\Users\btrah\OneDrive\Desktop\Stuff for Others\k-link\node_modules@vladfrangu\async_event_emitter\dist\index.cjs:2504:31)
at WebSocketShard.<anonymous> (C:\Users\btrah\OneDrive\Desktop\Stuff for Others\k-link\node_modules@discordjs\ws\dist\index.js:1190:51)
at WebSocketShard.emit (C:\Users\btrah\OneDrive\Desktop\Stuff for Others\k-link\node_modules@vladfrangu\async_event_emitter\dist\index.cjs:2504:31)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:391:10)
at process.processTicksAndRejections (node:internal/process/task_queues:91:21)
Node.js v24.11.1"
39 Replies
Ping me if you need me
Can you log interaction object using
console.log(interaction)?
Write it before if statement so it can run before creating errorDone
Can you send what you got on console?
Show the event loader where you're registering this event
This doesnt seem correct, how do you handle events?
Should look something like this
This is an example from the guide
In bot.js?
Could be
The main file
Because your
async execute(interaction) has interaction of type Client
Wherever it is. I don't know your file structureThe main file?
Yeah look for something like this
Most of the time people put their event loader in main file, if you didn't create another file for event loader its probably there
Thanks.
Most likely is.
So yeah I see why its not working
You see how you are running
event.excute(client, ...args) there?
That means you're passing the client object first and then the event argsSo remove โclientโ?
Really, you shouldn't pass that client at all, you shouldn't need it. The BaseInteraction class has the Client (and so do many other events)
Exactly, you can edit your execute file into
execute(client, interaction) so youll be fine if you don't want to edit your event loaderHow would i remove it?
That or add it before
interaction in async execute(client, interaction) but I prefer just removing itYou can already access
Client object with interaction.client so yeah you don't need itHow do i remove it.
^
Remove it from that
So just keep args there?
It should be
event.execute(...args)
There's 2 of them so don't forget bothDone.
Im gonna try it again.
It works. Thanks Guys!
Remove
client, part from your event loaders execute function so its gonna look like event.execute(...args)solved
Perfect. Now if you ever need the Client class. DJS attaches it to many objects so you can just do
Object.client to get it.
For example, interaction.client and message.client are 2 ways of getting itThanks Sam
Actually, another thing
Whats that mean?
Im new to databases
I prefer defining
let client = interaction.client so you wont need to write interaction over and over againKk
It's a network error. It means you lost connection to your database
Oh alright. Thx
How do I add an interaction for when a button is pressed?
Switch your InteractionCreate event to instead of returning early if it's not a command, instead do a chain of if, else if statements
That's at least one way of doing it
Okay.
How would I add the button logic here