How do assign a user's message to a variable in discord.py?

Viewed 127

So far I'm trying to assign the user's response to a question inside of a variable but an error messageenter image description here pops up every timeenter image description here I input the assignment name.

@client.command() async def Add(context):

Decalre variable as true to keep our main looop running

running = True while running:

# Prompt user to input course name
await context.send('Course name: ')
add_course = await client.wait_for('message', check=lambda message: message.author == context.author)
add_course_var = add_course.content

await add_course.channel.send(f'Course name registered: {add_course_var}')

# Prompt user to input assignment name
await context.send('Assignment name: ')
add_assignment_name = await client.wait_for('message', check=lambda message: message.author == context.author)
add_assignment_name_var = add_assignment_name.content

await add_assignment.channel.send(f'Assignment name registered: {add_assignment_name_var}')

# Prompt user to input deadline
await context.send('Due date(month, d: ')
add_deadline = await client.wait_for('message', check=lambda message: message.author == context.author)
add_deadline_var = add_deadline.content

await add_deadline.channel.send(f'Due date registered: {add_deadline_var}')
1 Answers

You haven't initialized the add_assignment variable in the code you have given. I'm guessing from the error, that add_assignment is actually a function, not a variable, which is why it's saying that it doesn't have a channel attribute. You want to change add_assignment to add_assignment_name so that it is taking the channel attribute from the add_assignment_name Message object.

Related