【问题标题】:Discord.js with Node.js connect to client fails but no errorsDiscord.js 与 Node.js 连接到客户端失败但没有错误
【发布时间】:2017-07-08 02:40:33
【问题描述】:

我在 nodeJS 中有 Discord.JS 模块

$ npm install --save discord.js

但是当我尝试使用它连接到用户时,它会失败。

这是我的 package.json

{
  "name": "discord-bot",
  "version": "0.0.1",
  "description": "A Discord Bot that comes with a lot of cool commands, music player and a betting game!",
  "main": "app/app.js",
  "scripts": {
    "start": "electron ."
  },
  "keywords": [
    "bot",
    "discord",
    "music",
    "betting-bot"
  ],
  "author": "Richard Olsen Sandberg",
  "license": "MIT",
  "devDependencies": {
    "electron": "^1.4.15"
  },
  "dependencies": {
    "discord.js": "^11.0.0"
  }
}

这是我的app/app.js代码

var ClassNode     = require ( __dirname + '/web/js/classnodes.js' ), /* This is something I have made to detect class names and make more beautiful outputs */
    Discord       = require ( 'discord.js' )                       , /* This is the offical Discord.JS library                                              */
    Client        = new Discord.Client (  )                        , /* This is a new instance of a Client from the Discord module                          */
    Electron      = require ( 'electron' )                         , /* This is to create applications that uses html, css, js, etc inside a chrome window  */
    BrowserWindow = Electron.BrowserWindow                         , /* This is the class that creates the Chrome Window                                    */
    app           = Electron.app                                   , /* This is the core off Electron                                                       */
    ipc           = Electron.ipcMain                               ; /* Send messages through windows                                                       */

/*****************************************/
/* I will not show content of Electron   */
/* stuff except from the login part to   */
/* make the question shorter             */
/*****************************************/



ipc.on ( 'login-attempt', ( event, args ) => {
  console.warning ( ClassNode.className + 'New sign in attempt triggered!' );

  if ( typeof args !== 'object' || args.username == undefined || args.password == undefined ) {
    console.error ( ClassNode.className + 'Invalid sign in attempt!' );
    event.sender.send ( 'login-attempt-error', ClassNode.className + 'Invalid request!' );
    return;
  }

  Client.login ( args.username, args.password, ( error, token ) => {
    if ( error ) {
      console.error ( ClassNode.className + 'Login attempt failed : ' + error );
      event.sender.send ( 'login-attempt-error', ClassNode.className + 'Login attempt failed : ' + error );
    } else {
      console.log ( ClassNode.className + 'Successfully created a connection!' );
      console.log ( ClassNode.className + 'Token : ' + token );
    }
  } );

} );

现在假设浏览器窗口发送了ipc.send('login-attempt', { username: 'discord@example.com', password: '123abc' })

输出:

电子::ipcMain |已触发新的登录尝试!

这意味着它从未执行过 Client.login 函数。

为什么它不这样做,我该如何解决?

【问题讨论】:

    标签: javascript node.js discord


    【解决方案1】:

    不再允许通过 Discord API 使用用户名和密码输入。您必须使用 OAuth 应用程序或存储在 localStorage 中的用户令牌,开发人员工具可以通过 Discord 客户端使用 Ctrl+Shift+ 访问该令牌I 在 Windows 上(在其他平台上使用相应的等效项)。

    here 所示,只接受一个令牌。

    API 变更说明here

    【讨论】:

      猜你喜欢
      • 2011-06-30
      • 2018-01-09
      • 1970-01-01
      • 1970-01-01
      • 2012-01-05
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 2014-06-27
      相关资源
      最近更新 更多