Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Discord.js。嵌入消息问题_Node.js - Fatal编程技术网

Node.js Discord.js。嵌入消息问题

Node.js Discord.js。嵌入消息问题,node.js,Node.js,当我尝试这段代码时,它不起作用。我做错了什么?代码错了吗?请帮忙,我对node.js很陌生 switch(args[0]){ case 'embed': const embed = new Discord.RichEmbed() function userInfo(user, msg){ addField('Player Name', message.author.username);

当我尝试这段代码时,它不起作用。我做错了什么?代码错了吗?请帮忙,我对node.js很陌生

 switch(args[0]){
        case 'embed':
            const embed = new Discord.RichEmbed()
            function userInfo(user, msg){
            addField('Player Name', message.author.username);
            msg.channel.sendEmbed(embed);}
            break;

方法
msg.channel.sendEmbed(嵌入);}-错误

您需要使用:

msg.channel.send(embed)
你的
功能用户信息(user,msg)
在做什么?我认为没有必要

如果您有两个或两个以上的
case
块,并尝试在每个块中嵌入常量,则必须得到错误
“标识符'embed'已声明”

在代码的第一部分的最后一部分,当您尝试添加字段时,使用的是消息。根据提供的代码,不清楚您之前定义了哪个变量(msgmessage),因此您需要自己更改它

如果代码的前一部分编写正确,此解决方案应该可以工作

 switch(args[0]){
     const embed = new Discord.RichEmbed()
        case 'embed':
            embed.addField('Player Name', msg.author.username);
            msg.channel.send(embed);
            break;

什么是错误消息?