discordjs / RPC

A simple RPC client for Discord
MIT License
466 stars 191 forks source link

o.createConnection is not a function #99

Closed fan2kendrick closed 3 years ago

fan2kendrick commented 3 years ago

Using vue-cli and discord-rpc, I have this error in the catch of my rpc.login(). Example code :

const rpc = new Client({ transport: 'ipc' })
rpc.login({ clientId: this.rpc.appId })
      .then(() => {
         console.log("Success")
       })
       .catch((err) => {
          console.log(err)
       });
philipjscott commented 3 years ago

You're likely trying to use this library in a web application. This library offers two transport types: ipc and websocket. Your application must be whitelisted by Discord to use websocket. Anyone can use ipc though: that's what you appear to be using.

IPC stands for "inter-process communiation": rather than communicating across a network using HTTP, you're communicating with the Discord client using a shared block of memory. Unfortunately, web applications cannot communicate via IPC (for security reasons).

The reason you're getting o.createConnection is not a function is because this library is attempting to use Node.js's net library, which isn't available for web applications. Here's the function the library is trying to call: https://nodejs.org/api/net.html#net_net_createconnection_path_connectlistener

BTW I don't really know what I'm doing as well so I might be partially wrong, sorry :P

fan2kendrick commented 3 years ago

Don't worry, and thanks for the answer. But now, if I want to use my app with vue-cli, I must use websocket and be whitelisted by Discord ?

philipjscott commented 3 years ago

Yeah; I'm not too familiar with the process