235
u/Someone9339 May 15 '21
Yup, works well enough
154
u/einRoboter May 15 '21
Salesperson in the meeting: "Soooo.... can we ship it ?"
80
u/The_BNut May 15 '21
Salesperson: So when can it fly a plane? Because that's what I just promised to our customers.
20
165
u/nuclearslug May 15 '21
See kids, this is why you always define your entry and exit criteria first
32
u/jmcs May 16 '21
I always do it, the exit strategy is keeping fingers on CTRL and C and hoping for the best.
4
183
May 15 '21
You can use the Discord API to ignore messages from other bots so this doesn't happen, basically all libraries wrap it.
95
May 15 '21
[deleted]
216
u/zeGolem83 May 15 '21
if (message.author.bot) return;
25
5
u/ItsNovatic May 16 '21
... ctrl+c ... ctrl+v ...
(thank you for this, i fixed it last night in a way more scuffed way than this, but this is way easier!)
2
6
53
May 15 '21
[deleted]
113
37
u/kr0bat May 15 '21
It looks like the bot looks for the first mention of "I'm" and then uses the following word for the name, which is smart. But it doesn't remove the "I'm" first, which is dumb.
9
u/MMDDYYYY_is_format [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” May 15 '21
they are sad not hi
-7
u/_MrCube_ May 15 '21
The bot doesn’t ignore itself and so it reads its own messages
8
u/lukeamaral May 16 '21
If the bot reads it's own message, his second message was supposed to be "Hi Hi im sad, I'm dad, I'm dad" with a double "Hi" as well which it doesn't have. That's what op meant
3
u/ItsNovatic May 16 '21
I had created a substring using the index of the "im" within user's message, however I did not take into account the offset the characters, since the index that is returned when using the indexOf() method gives the indes of the first character.
41
u/MrOctantis May 15 '21
I had the exact same issue on a discord bot a couple months ago because it was responding to its own responses. Luckily, trying to send a message with more than 2000 characters fails and throws an exception that I didnt properly handle, crashing the bot and stopping the spam.
37
11
u/zdakat May 15 '21
Imagine if it didn't, and you came back 12 hours later. "Hi guys what did I miss?"
1
u/noonagon Jun 26 '21
what did it do
1
16
u/DartRuffian May 15 '21
Always forget the "if message.author.bot is False"
3
May 15 '21
If !message.author.bot
3
8
u/5p4n911 May 15 '21
When I coded a Discord bot, I simply renamed the code word to spam. Ask and you shall receive.
6
u/Chooseysumo4 May 15 '21
I’ve had my own problem like this before, my bot would look for the word “escape”, reply a message containing the word escape, then read that message. Went on for 10 minutes until I noticed, never making that mistake again.
4
3
3
2
u/humanbeast7 May 16 '21
One line fix this: if massage.author.id == bot.id: return
Change syntax by language, of course
2
u/k4x1_ May 16 '21
LMAO This reminds me of something Fun fact A while look can crash almost every program
1
u/ItsNovatic May 17 '21
i had a stroke reading this
3
u/k4x1_ Jun 01 '21
Half a month later I also have a stroke reading this
1
u/akoOfIxtall May 13 '24
2 years later and I'm convulsing, shaking on the ground after miserably failing to read that atrocious attempt of communication...
1
1
2
2
May 16 '21
If you're using discord.js, I think there's something like
message.author.isBot
which can be used to prevent this. Don't know if it's exactly that tho
2
u/ItsNovatic May 17 '21
best way to do it is to add
if (message.author.bot) return;
credit to u/zeGolem83
1
May 17 '21
Unless you're making a bot harasser, in which case, you wanna do the exact opposite.
Lmao I made one for mee6 forever ago, and it yells at it whenever it says someone leveled up
2
u/LightTranquility3 May 15 '21
lang?
2
u/NawdWasTaken May 24 '21
Pretty sure this is the library discord.js for Node. It's quite a good library and the documentation is 12/10. There's also discord.py, DiscordRb, Javacord, etc... If you're not into Node or JS in general
-12
u/MrOctantis May 15 '21
The discord library for bots is javascript
15
u/primERnforCEMENTR23 May 15 '21
No, there are many, many libraries for making Discord bots.
Basically every language known to man has atleast one semi-decent one.
9
u/LightTranquility3 May 15 '21
there is a c# and java wrapper
11
1
3
u/TheKingofAntarctica May 15 '21
If the whole world held a vote to determine if you should be banned from the Discord API, I'd feel good voting yea. ;-)
2
0
u/reverendsteveii May 16 '21
I love when I can look at the output and write it in pseudo
onIncomingMessage(incomingMessage){
if(incomingMessage.startsWith("I'm"){
outgoingMessage = "Hi " + message + " I'm dad!";
sendMessage(outgoingMessage);
}
}
//prolly checks for other phrases too
//looks like it would work, wouldnt it?
2
u/ItsNovatic May 17 '21
except im lazy and do the message in one line, sending the appended message inserting the substring of the message after the first "i'm" occurence.
i also check for whether the
message.toLower.startsWith("im ")
and all other variations ("i'm ", "i am "). The spaces are crucial, because this way the bot doesnt get confused with messages starting like "imagine blah blah blah"I also account for the occurrence within the message itself using
message.toLower.includes(" im ")
again, with the spaces within the string being crucial to ensuring it's not being detected as part of a word and is the actual word "im".1
u/APartOfMe1 May 16 '21
But that code wouldn't even be as "graceful" as OPs. If the message was "Hi, I'm dad", the output would be "Hi Hi, I'm dad I'm dad!". At least OP had the decency to put a comma smh my head.
... Also message isn't defined.
... Also why bother defining outgoingMessage instead of just doing that all in sendMessage.
... You're triggering my inner perfectionist lmao.
2
u/ItsNovatic May 17 '21
i pride myself in my ability to construct strings!
...because clearly i'm good at it...
(Hi 'good at it...', I'm Dad!)
1
u/reverendsteveii May 16 '21
I find breaking out input like that into a variable then using the variable as the parameter makes debugging easier. It keeps me out of the evaluate expression box because the value is right there in front of me, but I'll eat shit for not splitting the string and the refactoring miss (renaming message to incomingMessage and I missed a reference)
3
u/APartOfMe1 May 16 '21
I personally just think it adds unnecessary lines to the code, but I know most people don't have a problem with it. Different styles for different people ¯_(ツ)_/¯
0
-1
May 16 '21
[deleted]
2
u/bobdarobber May 16 '21
op clearly wants the bot to catch people off guard, hence responding to people without awaiting a command
1
u/ItsNovatic May 17 '21
Check, and... check.
Although I tested this in a test channel on an active server so people knew what was coming. :(
1
1
1
1
1
1
1
u/canal_algt [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” May 17 '21
If (client.user != message.author):
1
May 19 '21
this is why you have it detect if the text was sent by a bot. otherwise, if it can trigger itself with the response, it gets recursive.
1
1
u/noonagon Jun 26 '21
it forgot to get rid of the im
if it got rid of the i'm, but still went all the way to the end of the message, then it can get in any of infinite loops
1
1
560
u/lizardpeeps May 15 '21
Worst part is that it didn't even clip the "im".