discord.io icon indicating copy to clipboard operation
discord.io copied to clipboard

get my bot to say something else if the command's from a specific user.

Open IchigoDemandsFurryBoobs opened this issue 6 years ago • 3 comments

i don't think this can be considered a issue but meh who cares. i want to make my bot say something if the command's writen by any user and say something different if the command's writen by a specific user if it's found in the current guild but i don't have knownledge on javascript lmao. i known how to make the bot mention a specific user and/or the user that wrote the command i'm using the following code after bot.on for normal messages:

    {
    if (message.toLowerCase() == "command to read")
        {
               console.log("message sent to the console when the bot answer");
                bot.sendMessage({
                    to: channelID,
                    message: "bot's answer"
                });
}	    }```

IchigoDemandsFurryBoobs avatar Mar 27 '18 07:03 IchigoDemandsFurryBoobs

i got this code

var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, {
    colorize: true
});
logger.level = 'debug';
var bot = new Discord.Client({
   token: auth.token,
   autorun: true
});
bot.on('ready', function (evt) {
    logger.info('Connected');
    logger.info('Logged in as: ');
    logger.info(bot.username + ' - (' + bot.id + ')');
});
bot.on('message', function (user, userID, channelID, message, evt)
{
    {
	if (bot.message.toLowerCase() == "test".from.userID == "380116205895417858")
        {
               console.log("test1");
                bot.sendMessage({
                    to: channelID,
                    message: "working?"
                });
}	    }
    {
    if (message.toLowerCase() == "test")
        {
               console.log("test");
                bot.sendMessage({
                    to: channelID,
                    message: "not working"
                });
}	    }
});

the bot logs in but it gives me the following error when typing test

	if (bot.message.toLowerCase() == "test".from.userID == "380116205895417858")
                                 ^
type error: cannot read properly 'toLowerCase'

IchigoDemandsFurryBoobs avatar Mar 28 '18 04:03 IchigoDemandsFurryBoobs

I believe this should work: if (message.toLowerCase() == "test" && userID == "380116205895417858") What I think it's doing is testing if everything after the first == can be lowercase, which it can't because of the second ==. But, with the new one, it will now test if the message is 'test' and if the userID is correct. I'm not sure if my explanation makes sense at all, but I tested it, and it should work now Also, with the second if statement, if you want to, I would replace it with else if. It'll make it so that only the intended will send. I hope this helps

trevor34 avatar May 04 '18 03:05 trevor34

You can use the 'userID' to compare it on the user id aka if(userID == "000000000000000"){ //Do something }

if (message.toLowerCase() == "hello"){ if(userID == "62725182628162828"){ bot.sendMessage({ to: channelID, message: "Hello user 1" }); } else{ bot.sendMessage({ to: channelID, message: "hello other users" } }

Here's an example:

KriskotooBG avatar Oct 08 '18 20:10 KriskotooBG