问题描述
我正在尝试创建一个通道切换记录器,该记录器允许我指定用于发布消息的通道。
例如,我创建了一个名为通道切换的TextChannel。现在,当用户更改语音通道时,它应该在此通道中显示一条消息。 (例如< USER>离开频道< CHANNEL>并加入了< CHANNEL>。
)
I'm trying to create a channel switch logger which allows me to specify a channel where the messages get posted.
So, for example, I create a TextChannel called "Channel Switches". When now a user changes voice channel, it should appear a message in this Channel. (eg. <USER> left channel <CHANNEL> and joined <CHANNEL>.
)
MY问题是:我没有错误,机器人没有响应...
MY PROBLEM IS: I get no errors and the Bot is not responding...
这是我的第一次尝试:
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");
}
});
推荐答案
您的机器人没有响应,因为客户端未初始化正确地。您正在这样创建客户端:
Your bot does not respond because the client is not initialized correctly. You're creating the client like this:
var bot = new Discord.Client({
token: auth.token, // <--
autorun: true // <--
});
问题是这些参数在discord.js中不存在,如。
登录到您的漫游器,请使用:
The problem is that these arguments do not exist in discord.js, as stated by the Client docs.
To log into your bot, please use Client.login()
:
var bot = new Discord.Client();
bot.login(auth.token);
这篇关于创建频道切换记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!