【发布时间】:2018-10-27 03:36:39
【问题描述】:
我正在开发一个 Discord 机器人,该机器人将通过 DM 接收投诉并将其发布到聊天室以供版主查看。由于某种原因,该类型被认为是未定义的。确切的错误文本是这样的:
TypeError: Cannot read property '44640...' of undefined
错误来自这一行:
if (bot.channel[channelID].type == 1)
如果频道 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 `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..
}
}
});
【问题讨论】:
-
我相信您正在尝试使用 2 个不同的库。
bot.sendMessage()不是 Discord.JS,但生成 Rich Embed 的方式看起来像 Discord.JS。您实际使用的是什么库? -
@AndréPaulo 我正在使用 Discord.io
标签: discord discord.io