[英]Im new at the discord bot scene and everytime i type in the terminal “node index.js” it doesnt work
I installed nod.js;discord.js and Im using Windows 10. I had already managed to get the bot online onto the Discord server before the extra commands.我安装了 nod.js;discord.js 和 Im 使用 Windows 10。在额外的命令之前,我已经设法让机器人在线到 Discord 服务器上。 If someone knows about it, you can write an answer.如果有人知道,您可以写一个答案。 (I deleted the owner ID and the Token) (我删除了所有者ID和令牌)
The Code is:该代码是:
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("");
The error message is:错误信息是:
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
Thanks in advance.提前致谢。
In any programming language, casing is very, very important.在任何编程语言中,大小写都非常非常重要。
Client
and client
are not the same thing. Client
和client
不是一回事。
const Client = new Discord.Client();
Here you've defined Client
, but you've never defined client
.在这里您已经定义Client
,但您从未定义过client
。 You should be using Client.login
, Client.user
etc.您应该使用Client.login
、 Client.user
等。
I recommend reading a basic tutorial我建议阅读基础教程
Welcome to programming!欢迎编程!
you forgot to erase the client id on the terminal.您忘记删除终端上的客户端 ID。 The error is saying that client is not defined
you must have misspelled the function name.错误是说client is not defined
您一定拼错了 function 名称。 you are using Client
and on the end write: client.login('')
which does not exists.您正在使用Client
,最后写: client.login('')
不存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.