我目前正在尝试从 discord.js 开始。我做了我的第一个机器人,我正在尝试做一些基本的事情。不知何故,我在自动回复后在我的频道聊天中得到了一个 undefined 。如果有人能弄清楚为什么会发生这种情况,那就太好了。bot.on('message', function (user, userID, channelID, message, evt) { 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; case 'hello': if (channelID == 632276762436567060) { bot.sendMessage ({ to: channelID, message: 'Check private message'+ bot.sendMessage ({ to: userID, message: 'hello' }) }) }; break; default: bot.sendMessage ({ to: channelID, message: 'Unknown Command' }); }MeToday 在 8:05 PM !你好 BOTToday 在 8:05 PM 查看私人消息undefined
1 回答
HUWWW
TA贡献1874条经验 获得超12个赞
您正在呼叫bot.sendMessage以将结果添加到不同sendMessage呼叫的消息中。它在消息中包含“未定义”,因为这是对bot.sendMessage.
相反,您应该将to: userID sendMessage另一个移出。
改变这部分:
bot.sendMessage
({
to: channelID,
message: 'Check private message'+
bot.sendMessage
({
to: userID,
message: 'hello'
})
})
对此:
bot.sendMessage
({
to: channelID,
message: 'Check private message'
});
bot.sendMessage
({
to: userID,
message: 'hello'
});
添加回答
举报
0/150
提交
取消