SyntaxError: Unexpected identifier 'Ready'

this is literally my first time coding and i keep getting the same error. what do i do? im literally trying to code a discord bot that has one slash command. ngl idek what my update is. i just did npm install discord.js or whatever
No description
16 Replies
d.js toolkit
d.js toolkit12mo 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!
nwqi
nwqiOP12mo ago
const { Client, Intents } = require('discord.js'); const { REST } = require('@discordjs/rest'); const { Routes } = require('discord-api-types/v10'); const express = require('express'); // Initialize Discord bot const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); // Discord bot token and client ID const TOKEN = '1'; const CLIENT_ID = '1'; const GUILD_ID = '1'; const rest = new REST({ version: '10' }).setToken(TOKEN); const app = express(); app.use(express.json()); // Express logging middleware app.use((req, res, next) => { console.log([${new Date().toISOString()}] ${req.method} ${req.url}); next(); }); // Handle interactions from Discord slash commands app.post('/interactions', (req, res) => { console.log('Received interaction request:', req.body); const { type } = req.body; switch (type) { case 1: const response = { type: 1, data: { content: 'Hello, Slash Command!' } }; console.log('Sending response:', response); res.status(200).json(response); break; case 2: // Handle type 2 interaction // ... break; case 3: // Handle type 3 interaction // ... break; default: console.log('Unknown interaction type:', type); res.status(400).send('Unknown interaction type'); break; } }); // Start the Express server app.listen(3000, () => { console.log('Express server is running on port 3000'); }); // Bot event handling client.on('ready', () => { console.log([${new Date().toISOString()}] Bot logged in as ${client.user.tag}); registerSlashCommands().catch(error => { console.error('Failed to register slash commands:', error); }); }); client.on('error', error => { console.error('Discord client error:', error); }); // Function to register slash commands async function registerSlashCommands() { console.log('Attempting to register slash commands...'); const commands = [ { name: 'hello', description: 'A simple hello command' } ]; try { await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands, }); console.log('Successfully registered slash commands.'); } catch (error) { console.error('Error registering slash commands:', error); } } // Login the bot client.login(TOKEN) .then(() => console.log('Initiating bot login...')) .catch(error => console.error('Bot login failed:', error)); my whole code if some can help with all of it then that would be great m first time coding thank you:) ive been attempting this code for literall 5 hours and every time i change stuff i get a new error very frustrating
treble/luna
treble/luna12mo ago
thats v13 code that code doesnt make much sense either
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/luna12mo ago
the client constructor is v13
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs12mo ago
Suggestion for @zander:guide Home: Introduction read more
nwqi
nwqiOP12mo ago
Thank you and yes I was using chatgpt to help me lol can yall help me? im getting this error while trying to do node index.js
nwqi
nwqiOP12mo ago
No description
nwqi
nwqiOP12mo ago
No description
nwqi
nwqiOP12mo ago
and thats my code (directly copied from the dicord.js guide)
treble/luna
treble/luna12mo ago
you uncommented a comment, and now you have a syntaax error which is basic js
nwqi
nwqiOP12mo ago
my first time coding can u help me fix it? idk what you mean
Squid
Squid12mo ago
discord.js is designed for people with fundamental JS knowledge if you don't understand what a comment is and isn't, then you have a lot of work to do before coding a bot
nwqi
nwqiOP12mo ago
i understand but im not coding a bot. i literally just wanna have a single slash command that does nothing. so i thought i could do that first i expected it to be extremely simple
treble/luna
treble/luna12mo ago
It is, if you know js
Want results from more Discord servers?
Add your server