简体   繁体   English

类型错误:每当我在不和谐的情况下向我的机器人输入 PM 时,都无法读取未定义的属性“id”

[英]TypeError: Cannot read property 'id' of undefined whenever i type a PM to my bot on discord

While just starting out coding my bot, I suddenly receive the error Cannot read property 'id' of undefined whenever I private message the bot.刚开始编写我的机器人时,我突然收到错误Cannot read property 'id' of undefined每当我给机器人发私信时。 The code and error stack are below.代码和错误堆栈如下。

var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');

// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
    colorize: true
});
logger.level = 'debug';

// Initialize Discord Bot
var bot = new Discord.Client({
   token: auth.token,
   autorun: true
});

bot.on('ready', function (evt) {
    logger.info('Connected');
    logger.info('Logged in as: ');
    logger.info(bot.username + ' - (' + bot.id + ')');
});

bot.on('message', function (user, userID, channelID, message, evt) {
    // Our bot needs to know if it will execute a command
    // It will listen for messages that will start with `!`
    if (message.substring(0, 1) == '!') {
        var args = message.substring(1).split(' ');
        var cmd = args[0];

        args = args.splice(1);
        switch(cmd) {
            // !ping
            case 'ping':
                bot.sendMessage({
                    to: channelID,
                    message: 'Pong!'
                });
            break;
            // Just add any case commands if you want to..
         }
     }
});
TypeError: Cannot read property 'id' of undefined

    at new Channel (C:\Users\PC\Desktop\Discord-Bot\node_modules\discord.io\lib\index.js:2529:25)

    at DiscordClient.handleWSMessage (C:\Users\PC\Desktop\Discord-Bot\node_modules\discord.io\lib\index.js:1889:33)

    at WebSocket.emit (events.js:189:13)

    at Receiver.ontext (C:\Users\PC\Desktop\Discord-Bot\node_modules\ws\lib\WebSocket.js:841:10)

    at C:\Users\PC\Desktop\Discord-Bot\node_modules\ws\lib\Receiver.js:536:18

    at Receiver.applyExtensions (C:\Users\PC\Desktop\Discord-Bot\node_modules\ws\lib\Receiver.js:371:5)

    at C:\Users\PC\Desktop\Discord-Bot\node_modules\ws\lib\Receiver.js:508:14

    at Receiver.flush (C:\Users\PC\Desktop\Discord-Bot\node_modules\ws\lib\Receiver.js:347:3)

    at Receiver.finish (C:\Users\PC\Desktop\Discord-Bot\node_modules\ws\lib\Receiver.js:541:12)

    at Receiver.expectHandler (C:\Users\PC\Desktop\Discord-Bot\node_modules\ws\lib\Receiver.js:499:31)```

I dont really have anything to do with discord.io, but looking at your error, it seems, that我真的与 discord.io 没有任何关系,但看着你的错误,似乎

var bot = new Discord.Client({
   token: auth.token,
   autorun: true
});

assigns undefined to your var bot .undefined分配给您的var bot At least thats what your error message tells you.至少那是你的错误信息告诉你的。

Looking at the package's example code from from https://www.npmjs.com/package/discord.iohttps://www.npmjs.com/package/discord.io查看包的示例代码

var Discord = require('discord.io');

var bot = new Discord.Client({
    token: "",
    autorun: true
});

bot.on('ready', function() {
    console.log('Logged in as %s - %s\n', bot.username, bot.id);
});

bot.on('message', function(user, userID, channelID, message, event) {
    if (message === "ping") {
        bot.sendMessage({
            to: channelID,
            message: "pong"
        });
    }
});

...I cant really find anything that you would've done wrong... so my guess is, that ......我真的找不到你会做错的任何事情......所以我的猜测是,那

var Discord = require('discord.io');

is getting the wrong path to discord.io进入discord.io路径错误

暂无
暂无

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

相关问题 Discord 机器人类型错误:无法读取未定义的属性“id” - Discord Bot TypeError: Cannot read property 'id' of undefined TypeError:尝试制作discord bot时无法读取undefined的属性'id' - TypeError: Cannot read property 'id' of undefined when trying to make discord bot 我正在尝试为我的 discord 机器人发出轮询命令,但它一直给我错误:“TypeError: Cannot read property 'push' of undefined” - I'm trying to make a poll command for my discord bot, but it keeps giving me the error: “TypeError: Cannot read property 'push' of undefined” JavaScript TypeError:无法读取未定义的属性'startsWith'-Discord Bot - JavaScript TypeError: Cannot read property 'startsWith' of undefined - discord bot TypeError:无法读取未定义 discord 机器人的属性“发送” - TypeError: Cannot read property 'send' of undefined discord bot discord 机器人错误类型错误:无法读取未定义的属性“名称” - discord bot error TypeError: Cannot read property 'name' of undefined TypeError:无法读取未定义的属性“获取” - Discord 机器人 - TypeError: Cannot read property 'get' of undefined - Discord bot 写入 discord bot 时出现“类型错误:无法读取未定义的属性‘发送’” - "TypeError: Cannot read property 'send' of undefined" while writing discord bot TypeError:制作我的不和谐机器人时无法读取未定义的属性“forEach” - TypeError: Cannot read property 'forEach' of undefined when making my discord bot “TypeError:无法读取未定义的属性‘id’”Discord.js 错误 - "TypeError: Cannot read property 'id' of undefined" Discord.js error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM