You have to split the incoming message text by spaces: The message "!rank Counter-Strike: Global Offensive"
would become an array of strings: [ "!rank", "Counter-Strike:", "Global", "Offensive" ]
. These are your parameters for the input. The first parameter is the command name. I suggest removing the “!” assuming you know it’s there like filtering messages to ensure they include “!” at the start. For this command, you would have the parameters except for the command joined back together and then check against the Twitch API and then reply. I’ve never done a Java or Python version of this, but here’s what a rough Javascript version looks like using the tmi.js library:
// The initial message.
let message = '!rank Counter-Strike: Global Offensive';
// "slice" off the first character and split the message by spaces.
let params = message.slice(1).split(' '); // [ 'rank', 'Counter-Strike:', 'Global', 'Offensive' ]
// Remove the first parameter, the command name, and save it here.
let command = params.shift(); // 'rank'
// A quick check to see if there are any parameters left.
let hasParams = params.length > 0; // true
// All of the remaining parameters joined back together with a space.
let allParams = params.join(' '); // 'Counter-Strike: Global Offensive'

In use it would look like this:
JS ES6 (newer, alternative syntax)
// A function to get some data about a game and its rank.
function getGameRank(name) {
return new Promise((resolve, reject) => {
// Here would be where you'd actually get the data from solve remote
// location on the internet via an API for example.
resolve({
name,
rank: Math.ceil(Math.random() * 100);
});
});
}
// Displays errors or whatever to the console with this function.
function catchError(err) {
console.log(err);
}
// The chat client has received a message. It is passed the IRC channel,
// ("#channel-name") the message, userstate data, and a boolean if the message
// was sent by this client.
client.on('message', (channel, userstate, message, self) => {
// Filter out own messages and messages not starting with "!".
if(self || message[0] !== '!') {
return;
}
// We "slice" off the first character and split the message by spaces.
let params = message.slice(1).split(' ');
// Remove the first parameter, the command name, and save it here.
let command = params.shift();
// A quick check to see if there are any parameters left.
let hasParams = params.length > 0;
// All of the remaining parameters joined back together with a space.
let allParams = params.join(' ');
// An anonymous helper function to reply back to the this channel with a
// simple format.
let reply = message => client.say(channel, message);
// Simply check if the command name is "rank" and that it has parameters
// available to use.
if(command === 'rank' && hasParams) {
// Do your stuff
getGameRank(allParams)
.then(data => reply(`The game "${data.name}" is ranked ${data.rank}!`))
.catch(catchError);
}
});
JS ES2015
// A function to get some data about a game and its rank.
function getGameRank(name) {
return new Promise(function(resolve, reject) {
// Here would be where you'd actually get the data from solve remote
// location on the internet via an API for example.
resolve({
name: name,
rank: Math.ceil(Math.random() * 100);
});
});
}
// Displays errors or whatever to the console with this function.
function catchError(err) {
console.log(err);
}
// The chat client has received a message. It is passed the IRC channel,
// ("#channel-name") the message, userstate data, and a boolean if the message
// was sent by this client.
client.on('message', function(channel, userstate, message, self) {
// Filter out own messages and messages not starting with "!".
if(self || message[0] !== '!') {
return;
}
// We "slice" off the first character and split the message by spaces.
var params = message.slice(1).split(' ');
// Remove the first parameter, the command name, and save it here.
var command = params.shift();
// A quick check to see if there are any parameters left.
var hasParams = params.length > 0;
// All of the remaining parameters joined back together with a space.
var allParams = params.join(' ');
// An anonymous helper function to reply back to the this channel with a
// simple format.
var reply = function(message) { return client.say(channel, message); };
// Simply check if the command name is "rank" and that it has parameters
// available to use.
if(command === 'rank' && hasParams) {
// Do your stuff
getGameRank(allParams)
.then(function(data) { return reply(`The game "${data.name}" is ranked ${data.rank}!`); })
.catch(catchError);
}
});
I could have a go at a Java or Python version if I need to.