Ask coding questions

← Back to all posts
What am I doing wrong?
MIfoodie (1)

Currently, I'm trying to make a discord bot that sends a random joke when you type in *joke. I'm really new to this whole coding bots thing so the wonderful person that responds to this, I ask of them to not name certain functions because I will not know what they mean. Thanks! :-)

Note: it's in python

Comments
hotnewtop
MuffinsTheCat (18)

Try this:

import random as ran
jokelist = ["joke1", "joke2", "joke3"]#continue
input("Press [Enter] and I will tell you a joke!")
print(jokelist[ran.randint(0,2)])#change the two to how many jokes there are minus 1
MIfoodie (1)

@MuffinsTheCat what does the
input("Press [Enter] and I will tell you a joke!")
do?

MuffinsTheCat (18)

@MIfoodie The user doesn't need to input anything, they just need to press enter

MIfoodie (1)

@MuffinsTheCat But I’m making a discord bot so a user has to put in a command (*joke)

MuffinsTheCat (18)

@MIfoodie this should work then:

import random as ran
jokelist = ["joke1", "joke2", "joke3"]#continue
command = input("Press [Enter] and I will tell you a joke!")
if command == "*joke":
  print(jokelist[ran.randint(0,2)])#change the two to how many jokes there are minus 1
elif command == "*other commands":
#other command
else: #if the command is not a bot command
  pass
MIfoodie (1)

@MuffinsTheCat Thanks you for your help, but I am going to take a break from this and get back to it when I'm better at python!

SixBeeps (5043)

Line 22, you're looking for this instead:

message.channel.send(random.choice(randomJokelist))