Lars Bergmann
Lars Bergmann

Reputation: 23

Edit message in Python

I want my bot to send a message and process it again after a certain period of time What I've already tried:

@client.command()
async def test(ctx):
    await ctx.send ('content')
    await asyncio.sleep(3)
    await message.edit(content="newcontent")

The error message:

AttributeError: module 'discord.message' has no attribute 'edit'

I use the following:

Upvotes: 0

Views: 219

Answers (2)

IPSDSILVA
IPSDSILVA

Reputation: 1839

You have a few errors in your code. One: there is a space between your ctx.send and your message ('content'). Your current code:

await ctx.send ('content')

Should be changed to:

await ctx.send('content')

The above doesn't need to be changed, although it is suggested. Also, make sure to define message:

message = await ctx.send('content')

Then you can edit the message:

await message.edit('new_content')

Upvotes: 1

Jacob Lee
Jacob Lee

Reputation: 4700

You would have to define message first.

@client.command()
async def test(ctx):
    message = await ctx.send("content")
    await asyncio.sleep(3)
    await message.edit(content="newcontent")

Upvotes: 3

Related Questions