Tmi.js in node.js question

one of my bots has a script where client.on(chat keyword) in my channel will call the function to join that users channel. the problem is some users can spam the keyword for my bot to join that channel and tmi will reject the command and throw an error. many easier ways to fix the issue but i was thinking the cleanest way would be to use get.channels and not trigger function if the channel is already on the list. anyone know how i could implement that?

with javascript you could handle the error code snippet, in any statement you take it with the catch and choose to treat or not then your code would fit correctly.

Checking locally whatever you already are in the channel or not is probably the cleanest way to go about it.

// untested..
client.on("chat", function (channel, userstate, message, self) {

    // Don't listen to my own messages..
    if (self) return;

	// ... logics
	
	const target = '#' + userstate.username;

	if(!client.getChannels().includes(target)){
		// target is not in the channel list
		client.join(target)
	}
    
});

You could also consider throttling / rate limiting the function if someone is abusing it (google it).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.