简体   繁体   English

运行 discord bot (JS) 时的错误代码

[英]Error code when run discord bot (JS)

Sorry if bad english!对不起,如果英语不好! First i run my discord bot and i use the tutorial from "Threebow" Then im in the last part of tutorial i got command !userinfo - show embed but when i lanched !userinfo i got these error in colsole首先我运行我的 discord bot 并使用“Threebow”中的教程然后我在教程的最后一部分我得到了命令 !userinfo - show embed 但是当我 lanched !userinfo 我在 colsole 中得到这些错误

(node:13056) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ReferenceError: messsage is not defined
(node:13056) [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.

This is my code discord bot code这是我的代码不和谐机器人代码

const botSettings = require("./botsettings.json");
const Discord = require("discord.js");
const prefix = botSettings.prefix;

const bot = new Discord.Client({disableEveryone: true})

bot.on("ready", async () => {
    console.log(`Bot is ready! ${bot.user.username}`);

    try {
        let link = await bot.generateInvite(["ADMINISTRATOR"]);
        console.log(link);
    } catch(e) {
        console.log(e.stack);
    }
});

bot.on("message", async message =>{
    if(message.author.bot) return;
    if(message.channel.type === "dm") return;

    let messageArray = message.content.split(" ");
    let command = messageArray[0];
    let args = messageArray.slice(1);

    if(!command.startsWith(prefix)) return;

    if(command === `${prefix}userinfo`) {
        let embed = new Discord.RichEmbed()
            .setAuthor(message.author.username)
            .setDescription("This is the user info!")
            .setColor("#9B59B6")
            .addField("Full username", `${message.author.name}#${message.author.discriminator}`)
            .addField("ID", message.author.id)
            .addField("Create At", message.author.createAt)

        messsage.channel.sendEmbed(embed);

        return;
    }
});

bot.login(botSettings.token);

Okay i get the answer!好的,我知道答案了! from Faisal Umair!来自费萨尔·乌梅尔! replace the更换

messsage.channel.sendEmbed(embed)

to

messsage.channel.sendEmbed(embed).catch(err => console.log(err));

Well.嗯。 Maybe try to read the Errors and actually understand them.也许尝试阅读错误并真正理解它们。

Your Wrote messsage.channel.send(embed);你写的messsage.channel.send(embed);
But u need to write it like message.channel.send(embed);但是你需要把它写成message.channel.send(embed);

I think you only need. 我想你只需要。 just a tip not an answer. 只是小费,不是答案。

messsage.channel.send(embed);

Found your problen.发现你的问题。 you defined message but then did messsage.channel.send(embed) .你定义了message但然后做了messsage.channel.send(embed) Change messsage to message.将消息更改为消息。 3 s'. 3 秒'。

Your code is erroring because in your function message.channel.send, you have message written with 3 s's.您的代码出错,因为在您的函数 message.channel.send 中,您的消息用 3 秒编写。 However, it's good practice to send embed in curly brackets, as RichEmbeds are changed in to Embed JSON before sending Updated line: message.channel.send({embed})但是,发送嵌入在大括号中是一种很好的做法,因为 RichEmbeds 在发送更新行之前更改为 Embed JSON:message.channel.send({embed})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM