Discord Bot Embed Variables come back as undefined

大兔子大兔子 提交于 2019-12-24 20:52:20

问题


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



来源:https://stackoverflow.com/questions/53183803/discord-bot-embed-variables-come-back-as-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!