Discord Bot Embed Variables come back as undefined

2019-08-17 15:43发布

问题:

This is my code and the values keep being undefined https://cdn.discordapp.com/attachments/501784044649054231/509529437419732994/unknown.png

This code is suppose to be

!rebirth 1 1 1 

and it should reply in embed

Collective cash 1
Lifecoins 1
Tokens 1

exports.run = (_client, message, args) => {
let {Cash} = args[0]; // Remember arrays are 0-based!.
let {Tokens} = args[1];
let {LifeCoins} = args[2];
const Discord = require('discord.js')

var embed = new Discord.RichEmbed()
    .setTitle("Rebirth")
    .setAuthor("Author Name", `${message.author.avatarURL}`)
    .setTimestamp()
    .addField("Collective Cash", `${Cash}`)
    .addField("Lifecoins", `${LifeCoins}`)
    .addField("Tokens", `${Tokens}`)
    .addBlankField(true)

message.channel.send({
    embed
})
}

回答1:

exports.run = (_client, message, args) => {
    let rest_of_the_string = message.content.slice('embed'.length); //removes the first part
    let array_of_arguments = rest_of_the_string.split(' '); //[Cash LifeCoints Tokens]
    const Discord = require('discord.js')

    var embed = new Discord.RichEmbed()
        .setTitle("Rebirth")
        .setAuthor("Author Name", `${message.author.avatarURL}`)
        .setTimestamp()
        .addField("Collective Cash", array_of_arguments[0])
        .addField("Lifecoins", array_of_arguments[1])
        .addField("Tokens", array_of_arguments[2])
        .addBlankField(true)

    message.channel.send({
        embed
    })
    }

Try that