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