Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = {
- data: new SlashCommandBuilder()
- // ... previous code for our SlashCommandBuilder.
- async execute(interaction) {
- // For simplicity, we'll declare our individual options.
- const authorName = interaction.options.getString('author-name')
- const authorIconURL = interaction.options.getString('author-icon-url')
- const authorUrl = interaction.options.getString('author-url')
- // We will now delcare our new EmbedBuilder, allowing us to add options later.
- const embed = new EmbedBuilder()
- // Now we need to add our authors. The easiest way to do this would be using
- // conditional (ternary) operators. Discord expects to receiver a string,
- // null, or undefined. With this knowledge, we can use an operator to pass
- // undefined if our option doesn't exist.
- // Let's not forget that we also need to make sure the author name exists.
- // Without our author name, we cannot use the other options since the name
- // is absolutely required if we're including an author in our embed.
- // With all of that in mind, let's implement it...
- if (authorName) {
- embed.setAuthor({
- name: authorName,
- iconURL: authorIconURL || undefined,
- url: authorUrl || undefined
- })
- }
- // You can do this for the rest of your options as well. If the string
- // option is required, you won't need to since it's guaranteed.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment