我的Discord.js正在运行,但不会响应命令

时间:2020-10-18 09:55:21

标签: javascript discord.js bots

我想为我的不和谐服务器创建一个建议机器人,所以我在人们“建议”时编写了代码,该机器人将为人们对该建议的投票提供一种舒适的投票方式,并且由于某种原因该机器人没有回应,我检查了其他人遇到的类似问题,但解决方案对我不起作用。

这是代码:

const { MessageEmbed } = require("discord.js")


module.exports = {
  name: "suggest",
  usage: "suggest <message>",
  description: "Send your Suggestion",
  category: "main",
  run: (client, message, args) => {
    
    if(!args.length) {
      return message.channel.send("Please Give the Suggestion")
    }
    
    let channel = message.guild.channels.cache.find((x) => (x.name === "suggestion" || x.name === "suggestions"))
    
    
    if(!channel) {
      return message.channel.send("there is no channel with name - suggestions")
    }
                                                    
    
    let embed = new MessageEmbed()
    .setAuthor("SUGGESTION: " + message.author.tag, message.author.avatarURL())
    .setThumbnail(message.author.avatarURL())
    .setColor("#ff2050")
    .setDescription(args.join(" "))
    .setTimestamp()
    
    
    channel.send(embed).then(m => {
      m.react("✅")
      m.react("❌")
    })
    

    
    message.channel.send("Sended Your Suggestion to " + channel)
    
  }
}

1 个答案:

答案 0 :(得分:0)

修复主要错误
在第11行上,您输入了if (!args.length) {
这将给您带来未定义的错误,从而导致其余代码无法正常工作。

用以下代码替换该行:

if(args.length < 1) {
    return message.channel.send("Please provide the Suggestion")
}

修复拼写错误
当您在代码末尾发送最终消息时

message.channel.send("Sended Your Suggestion to " + channel)

“已发送”不是一个字,应替换为“已发送”。