简体   繁体   English

我是 discord 机器人场景的新手,每次我输入终端“node index.js”时它都不起作用

[英]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. Clientclient不是一回事。

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.loginClient.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.

相关问题 您好,我已经用 Javascript 编写了一个 Discord 机器人,但是每次我输入节点 index.js 时它都不起作用 - Hello I have wirten an Discord Bot with Javascript but everytime i type in node index.js it doens`t work discord bot -- node index.js 问题 -- "client is not defined" - discord bot -- node index.js problem -- "client is not defined" 每当我运行“node index.js”时,我的不和谐机器人就无法连接 - My discord bot does not connect whenever I run 'node index.js' 为什么我的终端不允许我运行 node index.js - Why is my terminal not letting me run node index.js DisallowedIntents 如果我在终端中运行 discord 机器人 - DisallowedIntents if im run discord bot in terminal 我在 discord 上的代码中有错误,我使用 node 。 和节点 index.js - 错误:找不到模块 - I have a error in my code on discord and i use node . and node index.js - Error: Cannot find module 类型错误:不是 NODE JS DIscord Bot 中的 function - Type error: Is not a function in NODE JS DIscord Bot 我无法从我的 node.js firebase 函数 index.js 文件中验证大查询 - Im failing to authenticate Big query from my node.js firebase functions index.js file 如何让 $node index.js 在我的命令行中运行 index.js? - How can I get $node index.js to run index.js in my command line? 如何在 index.js [机器人的启动文件] 中创建 discord.js 命令,该命令在发送包含“hi”的消息时删除该消息 - How do I create a discord.js command in index.js [The bot's startup file] that deletes the message when a message that contains "hi" was sent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM