Help with a code from ChatGPT.

Hey, im mostly new to coding. I have a basic understanding of how the code should look. I can do basic reads. But this is my first time coding a bot. I used chat gpt along with the discord.js api docs Can anyone take a look at my code and help me correct the Gateway intents. I tried 2 different formats and neither of them work Yall can skim through the code and tell me other mistakes. but my main this is that when i run the code it tells me something with wrong with my gateway intent line of code
PS C:\Users\MAJ\Desktop\Bot 5> node index.js
C:\Users\MAJ\Desktop\Bot 5\index.js:47
const commands = client.commands.map((command) => command.data.toJSON());
^

TypeError: command.data.toJSON is not a function
at C:\Users\MAJ\Desktop\Bot 5\index.js:47:68
at C:\Users\MAJ\Desktop\Bot 5\node_modules\discord.js\node_modules\@discordjs\collection\dist\index.js:242:14
at Function.from (<anonymous>)
at _Collection.map (C:\Users\MAJ\Desktop\Bot 5\node_modules\discord.js\node_modules\@discordjs\collection\dist\index.js:240:18)
at Object.<anonymous> (C:\Users\MAJ\Desktop\Bot 5\index.js:47:38)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)

Node.js v21.1.0
PS C:\Users\MAJ\Desktop\Bot 5> node index.js
C:\Users\MAJ\Desktop\Bot 5\index.js:47
const commands = client.commands.map((command) => command.data.toJSON());
^

TypeError: command.data.toJSON is not a function
at C:\Users\MAJ\Desktop\Bot 5\index.js:47:68
at C:\Users\MAJ\Desktop\Bot 5\node_modules\discord.js\node_modules\@discordjs\collection\dist\index.js:242:14
at Function.from (<anonymous>)
at _Collection.map (C:\Users\MAJ\Desktop\Bot 5\node_modules\discord.js\node_modules\@discordjs\collection\dist\index.js:240:18)
at Object.<anonymous> (C:\Users\MAJ\Desktop\Bot 5\index.js:47:38)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)

Node.js v21.1.0
https://github.com/MAJ-TT/Bot5
GitHub
GitHub - MAJ-TT/Bot5: Test try for a discord bot. Only Hey, Help an...
Test try for a discord bot. Only Hey, Help and Ping commands - GitHub - MAJ-TT/Bot5: Test try for a discord bot. Only Hey, Help and Ping commands
6 Replies
d.js toolkit
d.js toolkit13mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
MAJ
MAJOP13mo ago
Discord.js: [email protected] Node: v21.1.0
Syjalo
Syjalo13mo ago
Don't use ChatGPT. It trained on data before September 2021 so its info is outdated. Follow our guide.
MAJ
MAJOP13mo ago
i actually did it alr but ran into the same kind of problem thats why i turned to chat gpt to see if i could get it from scratch. But i'd try it back and see how it goes
treble/luna
treble/luna13mo ago
A solid understanding of js is required before making a discord bot, so if you dont, #resources
MAJ
MAJOP13mo ago
Actually I did it, im proud of myslef.. I'm planing on making an economy bot, i got the base off so i'd go research more into it. If there is a docs realted to eco commands i'd appreciate a link is it fine if i gave my question back here? Its different from the initial question its now to do with the cool down edit: nvm fixed it
Want results from more Discord servers?
Add your server