【问题标题】:pastebin api createPasteFromFile error 'createPaste' of undefinedpastebin api createPasteFromFile 错误“createPaste”未定义
【发布时间】:2015-08-20 13:27:42
【问题描述】:

我正在为抽搐聊天创建一个带有节点的日志系统。当您键入“!logs user”时,它应该将正确的 user.txt 文件上传到 pastebin 并在聊天中给出一个到 pastebin 的链接。

我正在使用 pastebin-js 和 tmi.js

问题是当我输入 !logs user 时,它会在控制台中显示错误

C:\gempbot\node_modules\pastebin-js\bin\pastebin.js:137
        this.createPaste(data, title, format, privacy, expiration)
            ^
TypeError: Cannot read property 'createPaste' of undefined
    at C:\gempbot\node_modules\pastebin-js\bin\pastebin.js:137:13
    at fs.js:334:14
    at FSReqWrap.oncomplete (fs.js:95:15)

代码

client.on('chat', function (channel, user, message, self) {
   if (user["username"] === admins[0] || user["username"] === admins[1] || user["user-type"] === "mod" ) {
       if ( message.indexOf("!logs") >= 0 ) {
            var getNthWord = function(string, n){
            var words = string.split(" ");
            return words[n-1];
            }

            pastebin.createPasteFromFile('./logs/' + getNthWord(message, 2) + '.txt', 'logs for ' + getNthWord(message, 2))
                .then(function (data) {
                    // we have succesfully pasted it. Data contains the id 
                    console.log(data);
                    client.say(channel, 'Logs for ' + getNthWord(message, 2) + 'http://pastebin.com/' + data);
                })
                .fail(function (err) {
                    console.log(err);
                });



       }
   }
});

有没有人知道我该如何解决这个错误?我很困惑究竟是什么导致了这个问题。 这里是在 pastebin 中进行身份验证的其余代码(在我的代码的顶部)

var PastebinAPI = require('pastebin-js'),
    pastebin = new PastebinAPI({
      'api_dev_key' : 'censored',
      'api_user_name' : 'censored',
      'api_user_password' : 'censored'
    });

【问题讨论】:

    标签: javascript node.js pastebin


    【解决方案1】:

    这是模块中的错误。 this 在回调中使用,并且回调未绑定到 Pastebin 实例,因此 this 的值是错误的。有一个 PR 来解决这个问题here

    【讨论】:

    • 那真是太可惜了,希望他们尽快更新分支
    • PR 刚刚合并,新版本已发布。
    猜你喜欢
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    • 2011-08-25
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    • 2021-08-13
    相关资源
    最近更新 更多