javascript - 我是不和谐机器人场景的新手,每次我在终端输入“node index.js”时它都不起作用
问题描述
我安装了 nod.js;discord.js 并且我使用的是 Windows 10。在额外的命令之前,我已经设法让机器人在线到 Discord 服务器上。如果有人知道,您可以写一个答案。(我删除了所有者 ID 和令牌)
代码是:
const Discord = require(`discord.js`)
const Client = new Discord.Client();
const OwnerID = ""
const prefix = "!"
Client.on("ready", () => {
console.log("ich bin jetzt online!");
client.user.setPresence({ game: { name: `VAPE eSports Bot` ,type: 0} });
})
// welcome message
Client.on("guildMemberAdd", member => {
member.guild.defaultChannel.sbed("Wilkommen zu: " + member.guild.name + "Wir hoffe es gefällt euch hier")
})
Client.on("guildCreate", guild => {
console.log("Jemand hat den VAPE eSports Bot zu dem Server hinzugefügt, erstellt von " + guild.owner.user.username)
})
Client.on ("message", message => {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
let command = message.content.split(" ")[0];
command = command.slice(prefix.length);
let args = message.content.split(" ").slice(1);
if (command === "ping") {
message.channel.send(`Pong! Time took : ${Date.now() - message.createdTimestamp} ms`);
} else
if (command === "say" ) {
message.delete()
const embed = new Discord.RichEmbed()
.setColor(0x95D23)
.setDescription(message.author.username + " sagte: " + args.join(" "))
message.channel.send({embed})
} else
if (command == "help") {
const embed = new Discord.RichEmbed()
.setColor(0x954D23)
.setTitel("Befehl Liste:")
.addField("!help", "Wird dir alle Befehle zeigen")
.addField("!say [Text]", "Lässt den Bot etwas sagen")
message.channel.send({embed})
}
})
client.login("");
错误信息是:
PS C:\Users\49174\Documents\Discord bot> node index.js
C:\Users\49174\Documents\Discord bot\index.js:58
client.login("NzIyNTM4NTk2NzM2Njk2MzIw.XuzLYw.DOYUQLRU-Q9zwutex5w9-lbo3N4");
^
ReferenceError: client is not defined
at Object.<anonymous> (C:\Users\49174\Documents\Discord bot\index.js:58:1)
at Module._compile (internal/modules/cjs/loader.js:1200:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
at Module.load (internal/modules/cjs/loader.js:1049:32)
at Function.Module._load (internal/modules/cjs/loader.js:937:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
提前致谢。
解决方案
在任何编程语言中,大小写都非常非常重要。
Client
和client
不是一回事。
const Client = new Discord.Client();
在这里你已经定义了Client
,但你从来没有定义过client
。你应该使用Client.login
,Client.user
等等。
我建议阅读基础教程
欢迎编程!
推荐阅读
- laravel - 创建 laravel api 时需要处理的常见异常有哪些?
- octobercms - 十月CMS媒体路径中的双重主题名称
- xml - 安装 Wix 驱动程序?
- python - 网页抓取:遍历不同的页面总是从第一页返回内容
- c# - 作为单个 HTTP 请求的一部分执行顺序 MediatR 命令/查询的最佳实践?
- c - c客户端使用libwebsockets调用ibm-watson api
- sql - SQL查询查找不同ID下的重复电子邮件
- google-chrome - 如何阻止谷歌浏览器从请求的 URL 中删除 ../?
- angularjs - 如何在 Angular 和 AngularJs 混合应用程序中运行测试?
- ffmpeg - FFmpeg - 编写脚本来定义文本文件中每个单词的字体颜色?