Slash Commands

Hi. How can I regist slash commands to server? (Without REST)
26 Replies
d.js docs
d.js docs2y 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
Fyphen2y ago
Node Version: 18.9.0
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Fyphen
Fyphen2y ago
client.application.commands.create({ name: 'ping', description: 'Replies with ping', }) I can't regist with above?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Fyphen
Fyphen2y ago
I see If I use this code, I have to set up OAuth2?
MrMythical
MrMythical2y ago
rest is better btw and you just need applications.commands scope, no oauth tokens or whatever
Fyphen
Fyphen2y ago
humm application.commands? TypeError: Cannot read properties of null (reading 'commands') Error
MrMythical
MrMythical2y ago
then the client isn't ready rest is better because it doesn't need a websocket connection
Fyphen
Fyphen2y ago
How can I set up client?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Fyphen
Fyphen2y ago
yes I do it but I can't regist commands how can i?
MrMythical
MrMythical2y ago
You really should be using rest But put it in an event listener, ready
Fyphen
Fyphen2y ago
like this?
Fyphen
Fyphen2y ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
MrMythical
MrMythical2y ago
yes use that
Fyphen
Fyphen2y ago
Yes I did it but I can't regist command
MrMythical
MrMythical2y ago
did you run the file
Fyphen
Fyphen2y ago
yes
MrMythical
MrMythical2y ago
show how you run it in terminal and do you get any errors
Fyphen
Fyphen2y ago
no error But I can't search any commands
MrMythical
MrMythical2y ago
so what did you run in terminal
Fyphen
Fyphen2y ago
node register.js Yes I rename the file to register.js
MrMythical
MrMythical2y ago
what's in register.js
Fyphen
Fyphen2y 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
MrMythical2y ago
why do you have that at the bottom Also client id comes before guild id in arguments