#variables
24 messages · Page 1 of 1 (latest)
When you initialize your client you can give it extra properties like a connection to something.
async main() {
const client = new Client(...)
client.connection = new ConnectionToSomething()
await client.connection.connect()
await client.login()
}
main().catch(console.error)
When you handle interactions you can than do interaction.client.connection to access your connection since js Objects are mutable and are thus passed around in form of references.
async (interaction) => {
assert(interaction.client.connection instanceof ConnectionToSomething)
}
@lucid condor
My client is being defined inside of my index.
Would that mean I need to do the connection inside my index?
either that or you could use require/import in your index file to use the connection from another file
That is what I tried
oh my
I set is as var atm, I was just testing to see if there was a differnce
It just copy pasted it from the docs, so I haven't cleaned it yet
is connection->connect async ?
it is async
you can export a async function that creates the connection
module.exports = async function rconConnect() {
const conn = new Rcon(...)
await conn.connect()
return conn
}
then in client
const rconConnect = require(...);
async main() {
const client = new Client(...)
client.rcon = await rconConnect()
await client.login()
}
main().catch(console.error)
you should familiarize yourself with the js Promise API https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
try to avoid dangling promises
I got this to work. Thanks!