【问题标题】:Hello I have wirten an Discord Bot with Javascript but everytime i type in node index.js it doens`t work您好,我用 Javascript 编写了一个 Discord Bot,但每次我输入 node index.js 时它都不起作用
【发布时间】:2020-10-22 08:55:13
【问题描述】:

代码:

const Discord = require(`discord.js`);
const Client = new Discord.Client();


Client.on("message", function(message) {
        if(message.author.bot)return;

        if(message.content.startsWith("!say")){
            var text = message.content.split(" ").slice(1).join(" ");
            message.delete();
            if(!text) return message.channel.send("Du hast keine Nachricht eingegeben")
            let ambit = new Discord.MessageEmbed()
            .setTitle("ASSUME Gaming")
            .setDescription(text)
            .setColor("RED")
            .setImage(`https://cdn.discordapp.com/attachments/726775608721408070/727638443831591012/JPEG_20200628_201300.jpg`)
            message.channel.send(ambit)
            
        } else

        if(message.content === "!clear") {
            message.delete();
            message.channel.bulkDelete(100).then(() => message.channel.send("Nachrichten gelöscht"))
        } else

        if(message.content === "!counter") {
            message.channel.send(`\nTotal members: ${message.guild.memberCount}`);
        } else

        if(message.content === "!player") {
            let embed = new Discord.MessageEmbed()
            .setTitle("Player für ASSUME Gaming:")
            .setColor("RED")
            .addField("Fortnite Professionell", "")
            .addField("Fortnite Academy", "")
            .addField("Valorant Professionell", "")
            .addField("Valorant Academy", "")
            message.channel.send(embed)
        }

})

Client.on("ready", () => {
    console.log("ich bin jetzt online!")
    Client.user.setActivity("ASSUME Gaming", {type: "PLAYING"})
    
});

Client.login("(token)")

当我在终端输入“node index.js”启动机器人时的错误信息:

(node:6808) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided.
    at Client.login (C:\Users\49173\Documents\Assume Gaming\node_modules\discord.js\src\client\Client.js:204:52)
    at Object.<anonymous> (C:\Users\49173\Documents\Assume Gaming\index.js:49:8)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
(node:6808) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:6808) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

在终端中输入节点时的颜色也不是黄色,只有灰色。我知道存在“无效令牌”,但我有来自 Discord 开发人员门户的有效令牌。有谁知道可能是什么原因? 提前致谢

【问题讨论】:

  • 你有一个无效的令牌,这就是错误,所以就是这样。也许您从开发者门户复制了 Client SecretID 而不是 Bot User Token

标签: javascript node.js bots discord discord.js


【解决方案1】:

您的令牌不正确。确保您从 here 获得正确的令牌。

在不太可能的情况下,"(token)" 是您尝试使用的实际令牌,您需要使用上面链接中的令牌,而不仅仅是“(令牌)”`。

【讨论】:

    猜你喜欢
    • 2021-10-05
    • 2022-01-06
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-08
    • 1970-01-01
    相关资源
    最近更新 更多