Reputation: 303
My code for a command called ping
looks like this:
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
options: [
{
name: 'message',
description: 'Replies with your message!',
type: 'string',
required: false,
default: 'Pong!'
}
],
async execute(interaction, args) {
const [ message ] = args;
return interaction.reply(ping);
},
};
And currently, when I run this command (and deploy the slash commands first), there is no user enterable parameter, and it throws an error.
Upvotes: 1
Views: 3397
Reputation: 80
ik i answering too late, but you can create variable and use it to get content from the input:
const message = interaction.options.getString('message')
getString('message')
instead of the message inside brackets you can put whatever the name of the option or command is.
for example:
.addStringOption(option =>
option
.setName('off')
.setDescription('anti-spam is off')
)
now i need to get this 'off' inside option, so easy,
const SpamOn = interaction.options.getString('off')
Upvotes: 1
Reputation: 607
In order to access that parameter in a slash command, the user must be able to enter a parameter, so when you register the command, you must indicate how many parameters you want to receive and what type.
Documentation on how to add parameters to the commands here.
Documentation on how to read the arguments of a user-entered command here enter link description here.
Upvotes: 0