Sorts parameters provided after the prefix command. For example, "!sort a b avada kedavra" would make the bot message back "a avada b kedavra"
// authenticates you with the API standard library
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
if (context.params.event.content.startsWith('!sort')) {
let items = context.params.event.content.split(' ').slice(1); // Everything after the !sort
let sortedItems = items.sort((a, b) => {
if (a < b) {
return -1; // Returning -1 means "a" should go before "b"
} else if (a > b) {
return 1; // Returning 1 means "a" should go after "b"
} else {
return 0; // Returning 0 means "a" and "b" are equal
}
});
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Here are your sorted items: ${sortedItems.join(' ')}`
});
}