Closed Hacksawfred3232 closed 6 years ago
Yeah..... Heres the problem. according to the API docs, the removeListener command IS the only way to close the listener. And Discordie API mentions nothing about closing dispatcher listeners. so how does one get around this problem? Also that is the same page i used to try and fix this myself. @Dougley You see the problem here?
Fully closing the connection to Discord, and "closing the dispatcher" at the same time can be done with <Client>.disconnect()
.
Removing a listener from the dispatcher without terminating the entire connection can be done via <EventEmitter>.removeListener()
, as you've found. Keep in mind that the function must be named to remove it properly.
Client.Dispatcher.on('MESSAGE_CREATE', function onMessage (c) {
console.log('Got message!')
Client.Dispatcher.removeListener(onMessage)
})
Oh, so my problem was that i was not running it as a function. Okay, that is something i need to keep in mind. Thanks for the heads up! @Dougley
Okay, so complete noob here to JavaScript (And this API in general >_<) and i got a question to ask. How does one kill the MESSAGE_CREATE event listener - "i" - so i don't get this occurrence?: https://cdn.discordapp.com/attachments/214858024815296512/382568228704223233/unknown.png because it works perfectly fine, it just does not terminate the handler after its done. Here is a snippet of the code: ` case 'Tri#DNSlookup': var OrignSender = e.message.author.username e.message.channel.sendMessage("Handler started! Please post the URL in chat now."); client.Dispatcher.on("MESSAGE_CREATE", i => { if (i.message.author.username != OrignSender) {return;} else { dns.lookup(i.message.content, (err, address, family) =>{ var IP = address var IPV = family console.log("Dns lookup was requested. Requested IP of " + i.message.content + ". The result from lookup was " + IP + " IPV" + IPV); console.log("Completed Lookup at " + getDateTime()); i.message.channel.sendMessage("Request completed, Results as following:"); i.message.channel.sendMessage("Address of " + i.message.content + ": " + IP); i.message.channel.sendMessage("IP version: IPv" + IPV); i.message.channel.sendMessage("Handler stopped!");