node.js - 我在 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
。
我在这里也很新,对不起,如果我没有清楚地问一个问题......
解决方案
代码是正确的,但我discord
在文件的不同部分重新定义了......
我的建议是重新阅读代码!
推荐阅读
- java - ClassA 不能转换为 ClassA:java.lang.ClassCastException
- azure-devops - Azure Devops 中的仪表板查看测试结果的权限
- mysql - 尝试禁用外键检查,但不成功
- objective-c - 为什么不存在的外部变量的地址不等于null
- c# - 回滚后提交事务时会发生什么?
- python-3.x - 使用日期列将 excel 转换为 csv 无法按预期工作
- json - jq:迭代内部多个数组
- grpc - 如何对 grpc 服务进行负载测试,任何示例代码将不胜感激
- apache-spark - Univocity CSV Parser setDelimiter 方法的 Spark java.lang.NoSuchMethodError
- angular - 在 Angular 应用程序中定义和使用 xhook