How get arguments in slash command?

Registration:
const data = new SlashCommandBuilder()
.setName('balance')
.setDescription('Просмотр баланса')
.addUserOption(option => option.setName('user') .setDescription('Просмотр баланса другого пользователя'))
await bot.application.commands.create(data).catch(console.error);
const data = new SlashCommandBuilder()
.setName('balance')
.setDescription('Просмотр баланса')
.addUserOption(option => option.setName('user') .setDescription('Просмотр баланса другого пользователя'))
await bot.application.commands.create(data).catch(console.error);
Command:
const { Events } = require('discord.js');

module.exports = function balance(bot) {
bot.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;

console.log(???) // ARGUMENTS (user ID)
if (interaction.commandName === 'balance') {
await interaction.reply({embeds: [{title: 'Test', description: 'Testing', color: 0x00ff00, thumbnail: {url: bot.user.displayAvatarURL()}}]});
};
});

console.log('Ког balance загружен')
}
const { Events } = require('discord.js');

module.exports = function balance(bot) {
bot.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;

console.log(???) // ARGUMENTS (user ID)
if (interaction.commandName === 'balance') {
await interaction.reply({embeds: [{title: 'Test', description: 'Testing', color: 0x00ff00, thumbnail: {url: bot.user.displayAvatarURL()}}]});
};
});

console.log('Ког balance загружен')
}
No description
8 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
vo0ov
vo0ovOP14mo ago
discord.js - 14.13.0 Node.js - v21.1.0
treble/luna
treble/luna14mo ago
<Interaction>.options.getX(name) X being the type you expect the guide covers this too
vo0ov
vo0ovOP14mo ago
TypeError: interaction.options.getX is not a function
console.log(interaction.options.getX('user'))
console.log(interaction.options.getX('user'))
I understand
treble/luna
treble/luna14mo ago
X being the type you expect
whether thats a string, User, Member, etc
d.js docs
d.js docs14mo ago
guide Slash Commands: Parsing options - Command options read more
vo0ov
vo0ovOP14mo ago
What's the difference between User and Member?
d.js docs
d.js docs14mo ago
Despite sounding similar there is a distinct difference between users and members in Discord: - User: global Discord user data (global avatar, username, tag, id) - GuildMember: user data associated to a guild (guild, nickname, roles, voice, guild avatar, etc.) - Conversion: User ➞ GuildMember | GuildMember ➞ User * Note: Events received in cached guilds will often have both the member and user available, eg. interaction.user and interaction.member
Want results from more Discord servers?
Add your server