Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.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/3/wix/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
Javascript Discord.js如何生成建议命令?_Javascript_Node.js_Express - Fatal编程技术网

Javascript Discord.js如何生成建议命令?

Javascript Discord.js如何生成建议命令?,javascript,node.js,express,Javascript,Node.js,Express,我可以在Discord.js中做什么来生成建议命令?我的实际代码不起作用,我有两种建议:支持服务器和bot。 这是我的密码: if (command === "suggest"){ const type = args.join(" ") const thing = args.join(" ").slice(6) const thing2 = args.join(" ").slice(3) const suggestion = new Discord.RichEmb

我可以在Discord.js中做什么来生成建议命令?我的实际代码不起作用,我有两种建议:支持服务器和bot。 这是我的密码:

if (command === "suggest"){
    const type = args.join(" ")
    const thing = args.join(" ").slice(6)
    const thing2 = args.join(" ").slice(3)
    const suggestion = new Discord.RichEmbed()
       .setTitle("New suggestion!")
   .setAuthor(`${message.author.tag}`, `${message.author.avatarURL}`)
    .addField(`${message.author.tag}`, `suggested: ${thing}`)
    const suggestion2 = new Discord.RichEmbed()
       .setTitle("New suggestion!")
   .setAuthor(`${message.author.tag}`, `${message.author.avatarURL}`)
    .addField(`${message.author.tag}`, `suggested: ${thing2}`)
    if (!typ){
     message.reply("enter suggestion type, which you want to suggest!");
      return;
    }
            if (type === "server"){
               if (!thing){
     message.reply("enter thing you want to suggest!");
      return;
    }
      client.channels.get("channel_id").send(suggestion);
      return;
    }
    if (type === "bot"){
      if (!suggestion2){
     message.reply("enter thing you want to suggest!");
      return;
    }
      client.channels.get("another_channel_id").send(suggestion2);
      return;
    }
            else if (type !== "bot" || type !== "server"){
     message.reply("invalid suggestion type!"); 
    return;
        }
  }

当我输入时,它会输出“无效建议类型!”!建议

我不是discord.js的专家,但这应该有用!(它在我的服务器上运行!)

如果我能帮忙,那太好了


你也用过!==所以,若用户不是机器人,它不会发送消息。尝试使用===代替

如果这有帮助,我很高兴。我会编辑答案来解释。你不需要在每一行上都发表评论,我只是在寻找一个比“试试这个代码,它在我的机器上工作”更全面的答案。堆栈溢出的目标是为寻找特定编程问题的人们创建一个知识库。格式良好的问题和描述性答案。我要寻找的主要内容是一个描述,它解释了这段代码的工作原理。谢谢你的贡献
client.on('message', msg => {    //This runs when a message is sent.
const args = msg.content.slice(prefix.length).split(' ');  //Get the arguments
const command = args.shift().toLowerCase();  //Making the command non case-sensitive


if (command === 'suggest'){   //if command is suggest
const channel = msg.guild.channels.find(ch => ch.name === 'suggestions');  //finds the channel named suggestions 

channel.send('Suggestion:\n ' + args.join(' '))  //Sends the arguments
}     //Closes the if (command === 'suggest'){ 
});   //Closes the client.on('message',msg => {