N
N
NiicKz2021-04-18 20:54:46
Python
NiicKz, 2021-04-18 20:54:46

How to make it send multiple random messages?

I need that when a person writes a command, the bot sends several random words.
The code:

abc = [
      "a",
      "b",
      "c"
]

And when I write a command, the bot writes for example: bca

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2021-04-18
@NiicKz

from random import choice
import random

abc = [
      "a",
      "b",
      "c"
]

count_msg = random.randint(1,len(abc))

for x in range(0,count_msg):
  random_msg = choice(abc)
  print(random_msg)

In this form, the bot can send a random number of words from the abc list, although they can often be repeated. But since you are already writing a bot, then you already know Python, and there will be no problems fixing it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question