簡體   English   中英

帶有Node.js的Discord.js連接到客戶端失敗,但沒有錯誤

[英]Discord.js with Node.js connect to client fails but no errors

我在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函數。

為什么不這樣做,我該如何解決?

Discord API不再允許使用用戶名和密碼輸入。 您將必須使用OAuth應用程序或存儲在localStorage的用戶令牌,開發人員工具可以使用Windows上的Ctrl + Shift + I通過Discord客戶端訪問該令牌(開發人員工具可以通過Discord客戶端訪問該令牌)( 對於其他平台,請分別使用等效的令牌)。

如圖所示這里 ,只是象征性地被接受。

此處說明 API更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM