Embed Using Options Content
I can create a slash command that has multiple options. I just am drawing the short straw trying to have my bot respond to my slash command with a formatted embed using the content provided within the options. Any help would be much appreciated! DM's are open, and I am new to this so I will try my best to easily understand any help given.
31 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.[email protected] & v18.16.1
A slash command can have multiple options
You can add as many options up to Discord’s limit
Yeah, I can do that. I have a command with mutiple commands. I know how to have my bot respond to a slash command using an embeded message that is preset, but I want one that will format the content the member provides in the options.
Just use the interaction.options.getXOption() to get the option of x type
So like, .setDescription(interaction.options.getXOption('ign') ?
Would that be a valid line of code to get the content from my option called "ign"?
if ign is a string type, you need to use get
getString()
instead of the example getXOption()
So id I have a command that has these:
I could do
.setDescription(
getString(
'server'
),
);
Or something like that?
Your code up here is pretty much exactly what you need, so just make sure you're using an actual method for getting the option instead of the example you were given
But yeah, you can use whichever option you want for the description as long as it's a string-type option
So would this:
.setDescription(
Server: getString(
'server'
),
);
format it as:
Server: 1 & 2
if 1 & 2 was selected for the content of the 'server' option?
Assuming this is just pseudo-code, yeah, that would work like you're saying
Uhh I have no idea
Not familiar with the term pseudo-code
I just mean theoretical/non-literal code
Like don't literally copy-paste the block that you sent
Again, your code up here is pretty much perfect
Let me write up the full block of code for the command and I'll reply back to you.
I'll obviously run the bot and test it as well
I'm running into an issue with this:
const { SlashCommandBuilder, ApplicationCommandOptionType } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder([
{
name: 'report',
description: 'Files a report on a player.',
options: [
{
name: 'server',
description: 'Server 1 or 2',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'ign',
description: 'In-game Name',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'punishment',
description: 'Mute, Kick, Ban & Duration',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'reason',
description: 'Why they were punished?',
type: ApplicationCommandOptionType.String,
required: true,
},
{
name: 'message-link',
description: 'Copy & paste message link.',
type: ApplicationCommandOptionType.String,
},
{
name: 'picture',
description: 'Pictures of the rulebreak.',
type: ApplicationCommandOptionType.Attachment,
},
],
}],
interaction.reply("report")
)};
yeah that's not valid JS syntax
you can't just call a function in the middle of an object
So then back to this:
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('report')
.setDescription("Player Report"),
run: ({ interaction }) => {
interaction.reply("report");
},
};
I have my /report command, but it does not have any options. I have a reply, but it is not an embed.
I will post back anything I run into an issue with.
Also an entire file doesn't really tell me what "in need" means
That code recognizes my command /report and gives me all the same options I mentioned before, but when I try to run the command even with a simple reply to it, I get this:
interaction.response.send_message isn't a thing, so makes sense
use interaction.reply()
I replaced that chunk with interaction.reply('hello') , but the bot still does not respond..
you are returning if its a chatinputinteraction
I have this now. I have a slash command with options (required and non required), and with this code:
client.on('interactionCreate', (interaction) => {
if (interaction.commandName === 'report') {
interaction.reply('hello')
}
});
it responds to my command with hello.
I now need it to respond using a formatted embed using fetchReply() or getString()?