报告命令仅检测到命令本身,但未检测到用户

时间:2019-07-28 12:31:48

标签: discord.js

在脚本机器人的领域中有很多新事物,因此查阅了一些教程,并试图发出报告命令,当我编写!report时,它说“找不到用户”,但是当我编写完整命令时(!report @someone测试)它什么也没发送。

我曾尝试从GitHub复制代码,但无济于事,改变了很多东西,但仍然没有结果。

    //!report @ned this is the reason

    let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[1]));
    if(!rUser) return message.channel.send("Couldn't find user.");
    let rreason = args.join(" ").slice(22);


    let reportEmbed = new Discord.RichEmbed()
    .setDescription("Reports")
    .setColor("#15f153")
    .addField("Reported User", `${rUser} with ID: ${rUser.id}`)
    .addField("Reported By", `${message.author} with ID: ${message.author.id}`)
    .addField("Reported in", message.channel)
    .addField("Reported at", message.createdAt)
    .addField("Report reason", rreason);

    let reportschannel = message.guild.channels.get("603857301392195585")
    if(!reportschannel) return message.channel.send("Couldn't find reports channel.");


    message.delete().catch(O_o=>{});
    reportschannel.send(reportEmbed);

    return;
  }

没有错误,命令提示符中没有任何内容。

1 个答案:

答案 0 :(得分:-2)

1。。您忘记在嵌入中设置标题/作者。我不知道是否需要它,但您应该添加类似的内容。然后,您可以删除.setDescription()

// [...]
let reportEmbed = new Discord.RichEmbed()
 .setAuthor("Reports")
 .setColor("#15f153")
// [...]

2。。您可以省略message.delete()之后的部分,不需要.catch()

3。。最后删除return;。也是不需要的。


还要检查您是否正在运行此程序。 例如。使用调试消息。几乎每行之后,依次检查console.log("1")console.log("2")等,代码在哪里停止。

示例:

//!report @ned this is the reason

let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[1]));    
if(!rUser) return message.channel.send("Couldn't find user.");
console.log("1") // User exists
let rreason = args.join(" ").slice(22);
console.log("2") // No reason creating problems


let reportEmbed = new Discord.RichEmbed()
 .setAuthor("Reports")
 .setColor("#15f153")
 .addField("Reported User", `${rUser} with ID: ${rUser.id}`)
 .addField("Reported By", `${message.author} with ID: ${message.author.id}`)
 .addField("Reported in", message.channel)
 .addField("Reported at", message.createdAt)
 .addField("Report reason", rreason);

 let reportschannel = message.guild.channels.get("603857301392195585");
 if(!reportschannel) return message.channel.send("Couldn't find reports channel.");
 console.log("3") // Channel exists


 message.delete();
 console.log("4") // Message deleted
 reportschannel.send(reportEmbed);
 console.log("5") // Report message sent