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
• 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.Any errors ? And are you running this file inside
index.js
?yes
If so it's not recommended.
The guide now says clearly to use a seperate
deploy-comamnds.js
file for that purpose.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
what do if I writinh on replit?
writing*
my eanglish not well sry
Nothing changes if you use replit
Just copy paste the code from the guide and modify the commands part
yeah I was abt to say that
Personally I don't even recommend replit
But please follow the new guide to start developing your bot

Your code is missing the self executing function
I do not understand what are you talking about 

Just copy paste the code from the guide and modify the commands part
I don't have a PC or laptop, that's why I'm writing on replit

Yes
<: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