L
L
Lol Likovic2020-07-18 12:52:48
Python
Lol Likovic, 2020-07-18 12:52:48

How to remove "AttributeError: 'coroutine' object has no attribute 'content'" and "AttributeError: 'Message' object has no attribute 'user'" errors?

I write a bot on discord and it gives me this error:

File "C:\Users\nasty\Desktop\discord\test.py", line 21, in gdz
your_class = message_response.content
AttributeError: 'coroutine' object has no attribute ' content'

and this

File "C:\Users\nasty\Desktop\discord\test.py", line 20, in
message_response = client.wait_for('message', check=lambda m: m.user == ctx.user)
AttributeError: 'Message' object has no attribute 'user'

code itself:

client = commands.Bot( command_prefix = '!')



@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))


@client.command( pass_context = True )
async def gdz(ctx):
    await ctx.send('В каком вы классе? (8, 7, 9...)')
    message_response = client.wait_for('message', check=lambda m: m.client == ctx.client)
    your_class = message_response.content

    await ctx.send('По какому предмету? (Геометрия, Физика, Химия...)')
    message_response = client.wait_for('message')
    your_pred = message_response.content

    await ctx.send('Какой автор?(Пичугов, Вербицкая, Атанасян...)')
    message_response = client.wait_for('message', check=lambda m: m.client == ctx.client)
    your_auth = message_response.content

    await ctx.send('Какой номер?(100, 1564, 290...)')
    message_response = client.wait_for('message', check=lambda m: m.client == ctx.client)
    your_num = message_response.content



    if your_pred == 'Геометрия' and your_auth == 'Атанасян':
        await ctx.send('https://gdz.ru/' + 'class-8' + '/' + 'geometria' + '/' + 'atanasyan-8' + '/' + your_num + '-task/')
    elif your_auth == 'Пичугов':
        await ctx.send('https://gdz.ru/' + 'class-' + your_class + '/' + 'russkii_yazik' + '/' + 'pichugov-praktika-' + your_class + '/' + your_num + '-nom/')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nuchimik, 2020-07-18
@Lolik666

The class Messagehas no attribute useraccording to doc doc .
But there is an attributeauthor

A Member that sent the message. If channel is a private channel or the user has the left the guild, then it is a User instead.

At the expense of the first error, according to the dock again, the method client.wait_forreturns a string, and therefore contentit cannot have any. But in your case, the error is also that await is not specified before the coroutine, which is the method client.wait_for
Try this
message_response = await client.wait_for('message', check=lambda m: m.author== ctx.author)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question