Я работаю над ботом Discord, который будет принимать жалобы через DM и публиковать их в чате, чтобы их видели модераторы. По какой-то причине тип считается неопределенным. Точный текст ошибки таков:
TypeError: Cannot read property '44640...' of undefined
Ошибка исходит из этой строки:
if (bot.channel[channelID].type == 1)
Если сам идентификатор канала считается неопределенным, то я считаю, что это означает, что сам канал не определен.
Вот полный код функции:
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 `s!`
if (message.substring(0, 2) == 's!') {
var args = message.substring(2).split(' ');
var cmd = args[0];
args = args.splice(2);
switch(cmd) {
// s!ping
case 'ping':
bot.sendMessage({
to: channelID,
message: 'Pong!'
});
break;
case 'problem':
if (bot.channel[channelID].type == 1)
{
var embed = new Discord.RichEmbed()
.setAuthor(message.author.username, message.author.avatarURL)
.setDescription(message.content)
.setTimestamp(new Date())
.setColor('#C735D4');
//stores the sent message, along with the sender and the time of the message
client.channels.get(446393832066514947).send(embed);
//sends message to channel
}
// Just add any case commands if you want to..
}
}
});