创建频道切换记录器

时间:2018-08-04 19:02:10

标签: discord discord.js winston

我正在尝试创建一个频道切换记录器,允许我指定发布消息的频道。
因此,例如,我创建了一个称为“通道开关”的TextChannel。现在,当用户更改语音通道时,它应该在此通道中显示一条消息。 (例如<USER> left channel <CHANNEL> and joined <CHANNEL>.

我的问题是:我没有任何错误,机器人没有响应...

这是我的第一次尝试:

var Discord = require('discord.js');
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 + ")");
  console.log("Logged in as ${client.user.tag}!");
});

bot.on('voiceStateUpdate', (oldMember, newMember) => {
  let newUserChannel = newMember.voiceChannel
  let oldUserChannel = oldMember.voiceChannel


  if (!oldUserChannel && newUserChannel) {

    bot.channels.get('475330828466126848').send("User went form Channel" + oldUserChannel.name + "to the new" +
      newUserChannel.name + "Channel");

  }
});

1 个答案:

答案 0 :(得分:0)

您的漫游器没有响应,因为客户端未正确初始化。您正在这样创建客户端:

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

问题是,如Client docs所述,discord.js中不存在这些参数。
要登录您的机器人,请使用Client.login()

var bot = new Discord.Client();
bot.login(auth.token);