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

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 => {


如果我能帮助您,太好了!

另外,您还使用!==,因此,如果用户不是机器人,则它不会发送消息。尝试使用===代替!

关于javascript - Discord.js如何制作建议命令?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54332216/

10-14 13:34
查看更多