Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
857 views
in Technique[技术] by (71.8m points)

having optional args, for discord.js embed command

EDIT so i am trying to make a embed command and it will send a embed given the user input, a user will send the command like `.embed ?d description ?f footer ?i image url

so on

how do i make the options like ?d and ?f optional and the order want matter but it will create the embed on the given options

'example: .embed ?d description : this will create a embed with only a description'

i have already tried but i messed up here is the code https://hatebin.com/uzdsqwtqyw

but this outputs this :

enter image description here

question from:https://stackoverflow.com/questions/65858794/having-optional-args-for-discord-js-embed-command

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What you need to do is : go in your main file(like index.js) and set in top of code this :

const Discord = require('discord.js');

Then where command 'embed' is you need to set this :

if(command === 'embed'){
          client.commands.get('embed').execute(message, args, Discord);

Then in your command folder you will make a file named embed.js . In embed.js you need to set this code:

module.exports = {
    name: 'embed',
    description: 'Embed Test',
    execute(message, args, Discord){
        const newEmbed = new Discord.MessageEmbed()
        .setTitle('Your Title')
        .setColor('RANDOM')
        .setFooter('Some Footer here', 'another footer here' )
        .setDescription('> ?testa
' + '> ?testb
' + '> testc');
        message.delete();
        message.channel.send(newEmbed);
    }

});

And you get only the description after command and message with command ([prefix]embed) will delete after you post it !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...