如何修复Discord机器人离线?

时间:2020-05-17 09:43:39

标签: node.js discord.js

我最近对不协调的bot编码感兴趣,但我不知道此错误是什么问题,我尝试了各种解决方案,但都无法正常工作,并且我的bot在服务器上仍然脱机。

Error: Invalid transport, must be an object with a log method.
  at new LegacyTransportStream (C:\Users\redacted\Desktop\NinyaBot\node_modules\winston-transport\legacy.js:18:11)
  at DerivedLogger.add (C:\Users\redacted\Desktop\NinyaBot\node_modules\winston\lib\winston\logger.js:345:11)
  at Object.winston.<computed> [as add] (C:\Users\redacted\Desktop\NinyaBot\node_modules\winston\lib\winston.js:110:68)
  at Object.<anonymous> (C:\Users\redacted\Desktop\NinyaBot\bot.js:6:8)
  at Module._compile (internal/modules/cjs/loader.js:1133:30)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
  at Module.load (internal/modules/cjs/loader.js:977:32)
  at Function.Module._load (internal/modules/cjs/loader.js:877:14)
  at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
  at internal/main/run_main_module.js:18:47
  • 这是我在网上找到的代码。

    var Discord = require('discord.io');
    var logger = require('winston');
    var auth = require('./auth.json');
    // Configure logger settings
    logger.remove(logger.transports.Console);
    logger.add(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..
             }
         }
    });
    

2 个答案:

答案 0 :(得分:0)

我建议使用discord.js https://discordjs.guide/creating-your-bot/#creating-the-bot-file 使用此代码,它可以正常工作:

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

client.once('ready', () => {
    console.log('Ready!');
});

client.login('your-token-goes-here');

答案 1 :(得分:0)

控制台中显示的错误是关于第6行的,但也许不是导致 该机器人显示为脱机状态。

/Windows/Fonts/courbd.ttf

并且应该用类似的东西固定

C:/Windows/Fonts/courbd.ttf

观看\字。现在,传输需要一个新的对象才能工作,要进行着色,可以结合格式设置它。

在这里您可以找到有关https://www.npmjs.com/package/winston#common-transport-options的更多信息