Slash Commands

Hi. How can I regist slash commands to server? (Without REST)
26 Replies
d.js docs
d.js docs3y 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.
Fyphen
FyphenOP3y ago
Node Version: 18.9.0
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Fyphen
FyphenOP3y ago
client.application.commands.create({ name: 'ping', description: 'Replies with ping', }) I can't regist with above?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Fyphen
FyphenOP3y ago
I see If I use this code, I have to set up OAuth2?
MrMythical
MrMythical3y ago
rest is better btw and you just need applications.commands scope, no oauth tokens or whatever
Fyphen
FyphenOP3y ago
humm application.commands? TypeError: Cannot read properties of null (reading 'commands') Error
MrMythical
MrMythical3y ago
then the client isn't ready rest is better because it doesn't need a websocket connection
Fyphen
FyphenOP3y ago
How can I set up client?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Fyphen
FyphenOP3y ago
yes I do it but I can't regist commands how can i?
MrMythical
MrMythical3y ago
You really should be using rest But put it in an event listener, ready
Fyphen
FyphenOP3y ago
like this?
Fyphen
FyphenOP3y ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
MrMythical
MrMythical3y ago
yes use that
Fyphen
FyphenOP3y ago
Yes I did it but I can't regist command
MrMythical
MrMythical3y ago
did you run the file
Fyphen
FyphenOP3y ago
yes
MrMythical
MrMythical3y ago
show how you run it in terminal and do you get any errors
Fyphen
FyphenOP3y ago
no error But I can't search any commands
MrMythical
MrMythical3y ago
so what did you run in terminal
Fyphen
FyphenOP3y ago
node register.js Yes I rename the file to register.js
MrMythical
MrMythical3y ago
what's in register.js
Fyphen
FyphenOP3y ago
const { REST, SlashCommandBuilder, Routes } = require('discord.js'); const commands = [ new SlashCommandBuilder().setName('ping').setDescription('Replies with ping'), new SlashCommandBuilder().setName('server').setDescription('Replies with server info'), new SlashCommandBuilder().setName('user').setDescription('Replies with user info'), new SlashCommandBuilder().setName('down').setDescription('Shutdown the BOT'), new SlashCommandBuilder().setName('time').setDescription('Replies with now time'), ] .map(command => command.toJSON()); const rest = new REST({ version: '10' }).setToken("TOKEN"); rest.put(Routes.applicationGuildCommands("Guild ID", "Application ID"), { body: commands }) .then((data) => console.log(Successfully registered ${data.length} application commands.)) .catch(console.error); client.application.commands.create({ name: 'test', description: 'A test command', }) I have console log that "Success" But I can't
MrMythical
MrMythical3y ago
why do you have that at the bottom Also client id comes before guild id in arguments
Want results from more Discord servers?
Add your server