1

So I have ran into a problem where I get this error. In the documentation there is clearly a message attribute.

Here is my code (a part of it which doesn't work):

@client.command()
async def reg(message, oktaz):
message.message.delete()

How could I fix this?

2 Answers 2

1

Your code worked for me, except it wouldn't delete unless I added await on message delete (message.message.delete() -> await message.message.delete()), but even if I didn't add await, I wouldn't get that type of error. The only problem why it wouldn't delete the message for you is because you didn't add await. You shouldn't be getting an error saying "type object 'Context' has no attribute 'message'" if I'm correct. Are you sure you're not getting the error from a different part of the code that isn't the one you gave? Or maybe while pputting the code in stackoverflow you removed the part where the error is coming from in the reg command? Or you made a change but never saved?

@client.command()
async def reg(message, oktaz):
    await message.message.delete()
Sign up to request clarification or add additional context in comments.

1 Comment

Actually I don't know. I will try it later, the bot is running now, without this feature for now. I coded it for my school so everyone will get their class by their student ID. Too many logins to test it right now. But yeah, that's why I asked because I shouldn't get an error there. I will definietly try again.
0

ctx is the first parameter of every command. So you should change your code to this:

@client.command()
async def reg(ctx, message, oktaz):
    await ctx.message.delete()

3 Comments

The message attribute is the ctx here. The first attribute is the Context it doesn't matter what you use I think, or does it?
In this case, it matters because it thinks that you try to do something like that ctx.ctx.delete() because your parameter's name is same with the function. So if you try to do this, your question will be solved.
@Nurqm It does not matter if he used ctx or something else for the first parameter. It'll always be taken as the context argument no matter the name. To me his code seems fine, I've even tested it and no error. iroL, are you sure you're shown the actual part of the script. where the error is coming from? Perhaps yu edited the scrcode and then ran it without saving what you're edited? Perhaps it didn't delete the message for you because you forgot to use await on message.delete?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.