renesansz / discord-greeter-bot

My greeter bot for Discord
MIT License
49 stars 38 forks source link

Removing the "!" prefix — possible? #208

Closed texjer closed 5 years ago

texjer commented 5 years ago

I'd like to go prefixless on a simple autoresponder bot. Is this something I can customize the greeterbot to do?

NickXavier commented 5 years ago

I don't think so. There will be many commands you can do when you include !

Pyro-Druid commented 5 years ago

Yes. Replace:

if (message.substring(0, 1) == '!') {
        var args = message.substring(1).split(' ');
        var cmd = args[0];

        args = args.splice(1);

        switch(cmd) {
            // !ping
            case 'ping':
                bot.sendMessage({ to: channelID, message: 'Pong!' });
            break;
            default:
                bot.sendMessage({ to: channelID, message: 'Unknown command.' });
        }
}

with

var args = message.substring(0).split(' ');
var cmd = args[0];

args = args.splice(1);

switch(cmd) {
    // !ping
    case 'ping':
        bot.sendMessage({ to: channelID, message: 'Pong!' });
    break;
    default:
        bot.sendMessage({ to: channelID, message: 'Unknown command.' });
            } 

This will cause the bot to attempt to respond to any message (including it's own). As such you will also want to add an if statement checking if the message's userID is the bot's and ignoring it in that case.

If you want it responding to specific commands, edit to include this within the switch case:


case 'newCommand':
    bot.sendMessage({ to: channelID, message: 'responce to new command' });
break;
texjer commented 5 years ago

Oh, wow thank you, I'll give this a shot.