Reputation: 9
I got recently interested in discord bots coding and I don't know what the problem is with this error, I tried different solutions I can find but all of them are not working and my bot is still offline on the server.
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
this is the code i used that i found online.
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..
}
}
});
Upvotes: 0
Views: 16711
Reputation: 9370
I recommend using discord.js https://discordjs.guide/creating-your-bot/#creating-the-bot-file Use this code and it works just fine:
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
});
client.login('your-token-goes-here');
Upvotes: 0
Reputation: 140
The error showed in console is about line 6, however maybe is not what makes the bot appears offline.
logger.add(logger.transports.Console, {
colorize: true
});
And should be fixed with something like
logger.add(new logger.transports.Console({
format: winston.format.combine(
winston.format.colorize(),
winston.format.simple()
)
}));
Watch to new
word. Now transports require a new object to work and for colorize you can set it combining the formats.
Here you can find more info about it https://www.npmjs.com/package/winston#common-transport-options
Upvotes: 1