Ask coding questions

← Back to all posts
Hi there is there a message edit command so you can edit messages you have already written

HI there I am making a fantasy levitation system and I really want to try and use a command which lets me edit a message that is already in the console
There was one which said you could use
await message.edit(content="newcontent")
Which does not work
Thanks Levi H


From what I can gather, you're working on a Discord bot. What library are you using?


Hi there I am using python and am not making a bot i am simply interested whether there is a command for it


@hockneyle19 If you're not making a bot, then what are you doing? Anything you do in a Discord server programmatically must be done by a bot.


@SixBeeps I am not doing discord I am simply trying to make it edit a print message in the console when i press run


@hockneyle19 Woah there slow down, how did you manage to get your hands on Discord-like code then? What you provided was coincidentally really close to how Discord.js handles message editing.

Anyways, to understand how to change text in the console, you first have to understand how the console works. As is obvious enough, the console is a large grid and each cell in this grid holds characters. When you print some text, the terminal puts its contents on the row that it's looking at, then goes to the next row.

This is not too far off from how, say, a typewriter works. When you want to type a line onto the paper, you'd simply type the characters you want, hit the newline key, then reset the paper position so that when you go to type more text later, you start from the left.

Now, to change the printing position (in computing terms, this is called moving the cursor) you need to use an ANSI escape code. Those let you send commands to the terminal by printing a special sequence of characters.

Here's a simple method that handles that for you:

Now, to edit something you've printed, first move the cursor to wherever that text is in the terminal, print something, then move the cursor back to its original place.