首页 > 解决方案 > 我在 discord.js 中不断收到错误“未定义不和谐”,或者我没有收到机器人的响应。甚至没有错误/

问题描述

我正在使用 discord.js 编写一个不和谐的机器人。出于某种原因,它说Discord not defined错误或机器人没有响应。请问你能帮帮我吗?我以前从未遇到过这个错误。这是代码。我在同一个 main.js 文件中包含了这个命令:

if(cmd === `${prefix}help`){

  reporthelp = "Report a user. Requires a channel named `reports`to work!";
  kickhelp = "Kick a user from the server. Requires a channel named `incidents` to work; you must have the manage messages permission.";
  banhelp = "Ban a user from the server. Requires a channel named `incidents` to qork; toy need the BAN MEMBERS permission to use this command!";
  warnhelp = "**COMMAND COMING SOON!**";
  requiredperms = "**Embed Links, channel named `incidents`; channel named `reports`; channel named `suggestions`; Kick Members, Ban Members, Manage Roles, Manage Members.**"
  helpEmbed = new Discord.RichEmbed()

  .setDescription("  **__Help Is Here!__** ")
  .setColor("#936285")
  .addField("**/report @user <reason>**", reporthelp)
  .addField("**(COMING SOON)** /warn @user <reason>", warnhelp)
  .addField("**/kick @user <reason>**", kickhelp)
  .addField("**/ban @user <reason>**", banhelp)
  .addField("**/mytag**", "Shows you **your** discoord username#discrim and your user ID. Requires Embed Links permission.")
  .addField("**/invite**", "Get a linkto incite meto our server, and an invite link to my suppoer server")
  .addField("**/owner**", "see who currently owns the bot")
  .addField("**/git**", "**SOURCE CODE AVAILIBLE SOON**")
  .addField("**/token**", "View the bot's super secret bot token!")
  .addField("**/serverinfo**", "displays some basic server information!")
  .addField("**/botinfo**", "displays basic bot information!")
  .addField("**/ping**", "Get the bot to respond with `pong` ")
  .addField("**/hosting**", "Bot finds a good website for bot/web hosting")
  .addField("**/quotes**", "bot responds with some lovely quotes!")
  .addField("**__Required Permissions__**", requiredperms)
 // .addField("**COMING SOON!**/suggest <suggestion>", "suggest something. Requires channel named `suggestions`")
  .setTimestamp()
  .setFooter("Use /invite to invite me to your server!")


  return message.channel.send({embed: helpEmbed});


}

这就是我定义一切的方式:

const botconfig = require("./botconfig.json");
const tokenfile = require("./token.json");
const Discord = require("discord.js");

const bot = new Discord.Client({disableEveryone: true});

bot.on("ready", async () => {
  console.log(`${bot.user.username} is active in ${bot.guilds.size} servers!`);

  bot.user.setActivity("rewriteing main.js...", {type: "WATCHING"});

  //bot.user.setGame("Lookin' out for ya!");
});


bot.on("message", async message => {
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;

  const prefix = botconfig.prefix;
  const messageArray = message.content.split(" ");
  const cmd = messageArray[0];
  const args = messageArray.slice(1);

  const bicon = bot.user.displayAvatarURL;

我要么没有响应/错误,要么得到错误discord is not defined

我在这里也很新,对不起,如果我没有清楚地问一个问题......

标签: node.jsdiscorddiscord.js

解决方案


代码是正确的,但我discord在文件的不同部分重新定义了......

我的建议是重新阅读代码!


推荐阅读