首页 > 解决方案 > 我是不和谐机器人场景的新手,每次我在终端输入“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

提前致谢。

标签: javascriptbotsdiscord

解决方案


在任何编程语言中,大小写都非常非常重要。

Clientclient不是一回事。

const Client = new Discord.Client();

在这里你已经定义了Client,但你从来没有定义过client。你应该使用Client.loginClient.user等等。

我建议阅读基础教程

欢迎编程!


推荐阅读