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
d.js toolkit
d.js toolkit•3y 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.
Clouded
CloudedOP•3y ago
discord.js@14.11.0 & v18.16.1
Inky
Inky•3y ago
A slash command can have multiple options
d.js docs
d.js docs•3y ago
guide Slash Commands: Adding options read more
Inky
Inky•3y ago
You can add as many options up to Discord’s limit
Clouded
CloudedOP•3y ago
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.
Inky
Inky•3y ago
Just use the interaction.options.getXOption() to get the option of x type
Clouded
CloudedOP•3y ago
So like, .setDescription(interaction.options.getXOption('ign') ? Would that be a valid line of code to get the content from my option called "ign"?
Squid
Squid•3y ago
if ign is a string type, you need to use get getString() instead of the example getXOption()
Clouded
CloudedOP•3y ago
So id I have a command that has these:
Clouded
CloudedOP•3y ago
I could do .setDescription( getString( 'server' ), ); Or something like that?
Squid
Squid•3y ago
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
Clouded
CloudedOP•3y ago
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?
Squid
Squid•3y ago
Assuming this is just pseudo-code, yeah, that would work like you're saying
Clouded
CloudedOP•3y ago
Uhh I have no idea Not familiar with the term pseudo-code
Squid
Squid•3y ago
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
Clouded
CloudedOP•3y ago
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") )};
Squid
Squid•3y ago
yeah that's not valid JS syntax you can't just call a function in the middle of an object
Clouded
CloudedOP•3y ago
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.
d.js docs
d.js docs•3y ago
guide Slash Commands: Adding options read moreguide Popular Topics: Embeds read more
Clouded
CloudedOP•3y ago
I will post back anything I run into an issue with.
Clouded
CloudedOP•3y ago
@Squid I am in need again. Here is my code:
d.js docs
d.js docs•3y ago
To share long code snippets use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks.
Squid
Squid•3y ago
Also an entire file doesn't really tell me what "in need" means
Clouded
CloudedOP•3y ago
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:
chewie
chewie•3y ago
interaction.response.send_message isn't a thing, so makes sense use interaction.reply()
d.js docs
d.js docs•3y ago
method ChatInputCommandInteraction#reply() Creates a reply to this interaction. (more...)
Clouded
CloudedOP•3y ago
I replaced that chunk with interaction.reply('hello') , but the bot still does not respond..
chewie
chewie•3y ago
you are returning if its a chatinputinteraction
Clouded
CloudedOP•3y ago
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()?
d.js docs
d.js docs•3y ago
guide Slash Commands: Parsing options read more

Did you find this page helpful?