I have the following python code:
greetings = ["hi", "hello", "hey", "yo", "whats up"]
def greet(message):
greet = Random.choice(greetings)
return f"{greet} @{message.author}"
When I run this I get the error:
TypeError: choice() missing 1 required positional argument: 'seq'
Though I am clearly passing greetings into choice()
CodePudding user response:
It is not clear from your code what Random is.
However, if you import the random module and replace Random with random, your code should work.
Here is a fully working example (together with a Message class).
import random
greetings = ["hi", "hello", "hey", "yo", "whats up"]
def greet(message):
greet = random.choice(greetings)
return f"{greet} @{message.author}"
class Message:
def __init__(self, msg, author):
self.msg = msg
self.author = author
msg = Message('Hello', 'Peter')
print(greet(msg))
# Prints e.g.: 'hi @Peter'
CodePudding user response:
import random
greetings = "Hi", "Hello", "Hey", "Yo", "Whats up"
author = 'Stanly'
def greet(message):
greet = random.choice(greetings)
return f"{greet} @{author}!"
print(greet(greetings))
CodePudding user response:
The questions on the top is correct but here is one with Discord.PY (because I noticed some things that belong to it.) and also with async
import random
greetings = ["hi", "hello", "hey", "yo", "whats up"]
async def greet(message, greetings):
greet = random.choice(greetings)
return f"{greet}, @{message.author}"
if you are posting in stack overflow please tag more things other than just Python,
it helps more people try to understand what you are doing and what you want us to do.
