How register slash commands?

import { REST, Routes } from 'discord.js'; const commands = [ { name: 'ping', description: 'Replies with Pong!', }, ]; const rest = new REST({ version: '10' }).setToken(TOKEN); try { console.log('Started refreshing application (/) commands.'); await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands }); console.log('Successfully reloaded application (/) commands.'); } catch (error) { console.error(error); } This code doesnt working
16 Replies
d.js toolkit
d.js toolkit12mo ago
• 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.
KAVI
KAVI12mo ago
Any errors ? And are you running this file inside index.js ?
Kuray
Kuray12mo ago
yes
KAVI
KAVI12mo ago
If so it's not recommended. The guide now says clearly to use a seperate deploy-comamnds.js file for that purpose.
Kuray
Kuray12mo ago
and here the error /home/runner/idk/index.js:15 await rest.put(Routes.applicationCommands(proces.env.ID), { body: commands }); ^^^^^ SyntaxError: await is only valid in async functions and the top level bodies of modules
Kuray
Kuray12mo ago
what do if I writinh on replit? writing* my eanglish not well sry
chewie 🌈
chewie 🌈12mo ago
Nothing changes if you use replit Just copy paste the code from the guide and modify the commands part
KAVI
KAVI12mo ago
yeah I was abt to say that ohno Personally I don't even recommend replit But please follow the new guide to start developing your bot
chewie 🌈
chewie 🌈12mo ago
Your code is missing the self executing function
Kuray
Kuray12mo ago
I do not understand what are you talking about cryingfloosh
chewie 🌈
chewie 🌈12mo ago
Just copy paste the code from the guide and modify the commands part
Kuray
Kuray12mo ago
I don't have a PC or laptop, that's why I'm writing on replit
KAVI
KAVI12mo ago
this and remove that code from your main index file and write it inside a separate file like the guide suggests So how are you writing the code then ? on mobile ? <:teri_afraid:723908621771210782>
Kuray
Kuray12mo ago
Yes
KAVI
KAVI12mo ago
<:A_HuTaoSalute:792062698481385492> best of luck then mate. If you follow the guide you won't be getting any errors and the bot will be online