简体   繁体   中英

Discord.js embed command

Some Info:

I've been trying to make a command that makes the bot embed a title and description (ex. !embed (Title here) | (Description here)) so anyone who has the right permissions can use the bot to embed but I'm either really dumb or extremely persistent on a so called lead in my code that leads to nowhere.

Problem:

Cannot seem to get the title input and the description input to not mess with each other in a weird way (Putting the title into the description or the other way around) the vertical slash is suppose to be the divider between the title and description but I can't get it to work no-matter how hard I mess with my code.

Code:

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

module.exports.run = async (client, msg, args) => {

    args.slice(0).join(" ")

    let embed = new Discord.MessageEmbed()
    .setColor("RANDOM")
    .setTitle(args[0])
    .setDescription(args.slice(1).join(" "))

    msg.channel.send(embed);
}

module.exports.help = {
    name: "embed"
}

The error is just here args.slice(0).join(" ") .

You need to store the new value of the args into the args value to update it.

So change that to: args = args.slice(0).join(" ")

And normally it will perfectly work!

Edit:

You can use a specific typo in the command like -command -t Title with multiple words -d Description with multiple words . Then you can adapt your code.

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

module.exports.run = async (client, msg, args) => {

    args.slice(0).join(" ")

    let embed = new Discord.MessageEmbed()
    .setColor("RANDOM")
    .setTitle(args.join(" ").split("-t")[1].split("-d")[0].trim())
    .setDescription(args.join(" ").split("-d")[1].trim())

    msg.channel.send(embed);
}

module.exports.help = {
    name: "embed"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM